sebastian-lenz / craft-linkfield

Link field for Craft 3
MIT License
122 stars 66 forks source link

Fields’ isEmpty() method has been deprecated. Use isValueEmpty() instead. #15

Closed seandelaney closed 6 years ago

seandelaney commented 6 years ago

Getting the above error when trying to save entries uses the Link field on Craft CMS 3.0.0-RC15.

Here is the stack trace:

25 | Deprecation error: Fields’ isEmpty() method has been deprecated. Use isValueEmpty() instead. Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/base/Field.php:315
-- | --
typedlinkfield\fields\LinkField::isValueEmpty(typedlinkfield\models\Link, craft\elements\MatrixBlock) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/base/Element.php:1037
craft\elements\MatrixBlock::isFieldEmpty("href") Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/base/Element.php:776
craft\elements\MatrixBlock::__call("isFieldEmpty:href", [typedlinkfield\models\Link])
call_user_func([craft\elements\MatrixBlock, "isFieldEmpty:href"], typedlinkfield\models\Link) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/validators/Validator.php:444
typedlinkfield\validators\LinkFieldValidator::isEmpty(typedlinkfield\models\Link) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/validators/Validator.php:264
typedlinkfield\validators\LinkFieldValidator::validateAttributes(craft\elements\MatrixBlock, ["field:href"]) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/base/Model.php:367
craft\elements\MatrixBlock::validate() Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/fields/Matrix.php:527
craft\fields\Matrix::validateBlocks(craft\elements\Entry, null) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/base/Element.php:1019
craft\elements\Entry::validateCustomFieldAttribute("field:slider", [craft\fields\Matrix, "validateBlocks", null], yii\validators\InlineValidator)
call_user_func([craft\elements\Entry, "validateCustomFieldAttribute"], "field:slider", [craft\fields\Matrix, "validateBlocks", null], yii\validators\InlineValidator) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/validators/InlineValidator.php:72
yii\validators\InlineValidator::validateAttribute(craft\elements\Entry, "field:slider") Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/validators/Validator.php:267
yii\validators\InlineValidator::validateAttributes(craft\elements\Entry, ["field:slider"]) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/base/Model.php:367
craft\elements\Entry::validate() Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/services/Elements.php:373
craft\services\Elements::saveElement(craft\elements\Entry) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/controllers/EntriesController.php:539
craft\controllers\EntriesController::actionSaveEntry()
call_user_func_array([craft\controllers\EntriesController, "actionSaveEntry"], []) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/base/InlineAction.php:57
yii\base\InlineAction::runWithParams(["p" => "admin/entries/homepage/2-homepage"]) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/base/Controller.php:157
craft\controllers\EntriesController::runAction("save-entry", ["p" => "admin/entries/homepage/2-homepage"]) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/web/Controller.php:74
craft\controllers\EntriesController::runAction("save-entry", ["p" => "admin/entries/homepage/2-homepage"]) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/base/Module.php:528
craft\web\Application::runAction("entries/save-entry", ["p" => "admin/entries/homepage/2-homepage"]) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/web/Application.php:237
craft\web\Application::runAction("entries/save-entry", ["p" => "admin/entries/homepage/2-homepage"]) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/web/Application.php:445
craft\web\Application::_processActionRequest(craft\web\Request) Called from /Users/seandelaney/Sites/ims/vendor/craftcms/cms/src/web/Application.php:221
craft\web\Application::handleRequest(craft\web\Request) Called from /Users/seandelaney/Sites/ims/vendor/yiisoft/yii2/base/Application.php:386
craft\web\Application::run() Called from /Users/seandelaney/Sites/ims/web/index.php:26
seandelaney commented 6 years ago

Simple fix though, which I've added locally so I can continue working...

Path: /vendor/sebastianlenz/linkfield/src/models/InputLinkType.php

  /**
   * @param LinkField $field
   * @param Link $link
   * @return array|null
   */
  public function validateValue(LinkField $field, Link $link) {
    if ($this->isValueEmpty($link)) {
      return null;
    }
seandelaney commented 6 years ago

Please see: https://github.com/craftcms/cms/issues/2575