Skip to content

[5.x]: Link field errors on changing Allowed Link Types #15542

@rungta

Description

@rungta

What happened?

Steps to reproduce

  1. Create a new Link field, allow URL link type
  2. Add the link field to an entry type
  3. Save an element with a URL
  4. Edit the Link field, enable any other link type(s) but disable the URL link type
  5. Open the element’s Edit page

Expected behavior

Not sure, but some ideas:

  • Warn about this behaviour on the field’s settings page
  • Handle the error more gracefully? There will probably be multiple scenarios where the field has data saved in a link type that is no longer enabled or available for various reasons.

Actual behavior

yii\base\ErrorException: Undefined array key "url" in /var/www/html/vendor/craftcms/cms/src/fields/Link.php:330
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/var/www/html/v...', 330)
#1 /var/www/html/vendor/craftcms/cms/src/fields/Link.php(330): craft\web\ErrorHandler->handleError(2, 'Undefined array...', '/var/www/html/v...', 330)
#2 /var/www/html/vendor/craftcms/cms/src/base/Element.php(6155): craft\fields\Link->normalizeValue('https://example...', Object(craft\elements\Entry))
#3 /var/www/html/vendor/craftcms/cms/src/base/Element.php(4696): craft\base\Element->normalizeFieldValue('legacyUrl')
#4 /var/www/html/vendor/craftcms/cms/src/base/Element.php(4678): craft\base\Element->getFieldValue('legacyUrl')
#5 /var/www/html/vendor/craftcms/cms/src/base/Element.php(2476): craft\base\Element->clonedFieldValue('legacyUrl')
#6 /var/www/html/vendor/yiisoft/yii2/base/ArrayableTrait.php(126): craft\base\Element->craft\base\{closure}(Object(craft\elements\Entry), 'legacyUrl')
#7 /var/www/html/vendor/craftcms/cms/src/base/Element.php(2493): craft\base\Element->traitToArray(Array, Array, false)
#8 /var/www/html/vendor/craftcms/cms/src/web/View.php(675): craft\base\Element->toArray(Array, Array, false)
#9 /var/www/html/vendor/craftcms/cms/src/base/Element.php(3789): craft\web\View->renderObjectTemplate('{{ (_variables....', Object(craft\elements\Entry))
#10 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(314): craft\base\Element->getPreviewTargets()
#11 [internal function]: craft\controllers\ElementsController->actionEdit(Object(craft\elements\Entry), 772)
#12 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#13 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#14 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('edit', Array)
#15 /var/www/html/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('elements/edit', Array)
#16 /var/www/html/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('elements/edit', Array)
#17 /var/www/html/vendor/craftcms/cms/src/web/Application.php(317): yii\web\Application->handleRequest(Object(craft\web\Request))
#18 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#19 /var/www/html/web/index.php(12): yii\base\Application->run()
#20 {main}

Craft CMS version

5.3.4

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions