Field content['#options'] missing after upgrade to core 10.2.3

Created on 21 February 2024, 9 months ago
Updated 23 February 2024, 9 months ago

Link fields, and likely other text fields, are missing content['#options'].
We discovered this on our site after upgrading from core v10.2.2 -> core v10.2.3.

Specifically for us, link fields with additional attributes are no longer rendering properly. We are currently using the link_attributes module to add these additional attributes, which seems to be failing because the Field content['#options'] no longer exists.



Here is an example of a link field object in drupal core 10.2.2:

0 array:2 [▼
"content" => array:4 [▼
"#type" => "link"
"#title" => "Meeting Documents"
"#options" => array:2 [▼
"attributes" => array:2 [▶]
"external" => true
]
"#url" =>
Drupal\Core
\
Url {#3654 ▶}
]
"attributes" =>
Drupal\Core\Template
\
Attribute {#3815 ▼
#storage: []
}
]

Here is an example of the same field in drupal core 10.2.3:
Notice how item.content[#options'] is missing.

0 array:2 [▼
"content" => array:3 [▼
"#type" => "link"
"#title" => "Meeting Documents"
"#url" =>
Drupal\Core
\
Url {#3775 ▶}
]
"attributes" =>
Drupal\Core\Template
\
Attribute {#3699 ▼
#storage: []
}
]

💬 Support request
Status

Closed: works as designed

Version

10.2

Component
Options 

Last updated about 9 hours ago

No maintainer
Created by

🇺🇸United States cdupree

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @cdupree
  • 🇺🇸United States cdupree

    Is the ['#options'] array generated through core or is it generated through the modules that use it? Please advise if this bug is being reported in the wrong place, thanks.

  • Status changed to Needs work 9 months ago
  • 🇺🇸United States cdupree
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Which formatter are you using?

  • 🇺🇸United States cdupree

    I'm not sure, I'm not a seasoned Drupal dev. How can I determine which formatter I'm using?

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    See related issue, might be a problem in your theme
    What sort of content are you using the link field on- menu links?

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Linking where the bug was fixed in core

  • Status changed to Needs review 9 months ago
  • 🇺🇸United States COBadger

    It's not clear to me where this was addressed in 10.2.x, so I'm attaching a patch that I re-rolled from the 11.x patch for use against 10.2.3 in case it's useful to anyone.

    Marking this as 'Needs review', though perhaps this issue could be closed if it's addressed in the linked issue.

  • Status changed to Needs work 9 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Status changed to Needs review 9 months ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Link attributes module is still passing tests on 10.2.3

    If you have this problem it is likely you have a theme preprocess hook or template that is accessing link['optiions'] the fix in core was to remove duplicates between link['optiions'] and link['url']->get options()

    You should be using the options on the url object, not the render array

  • 🇺🇸United States cdupree

    Yes, the linked issue #3423171 was a duplicate of this problem.
    We did a find and replace in our theme and replaced all instances of ['#options']['attributes'] with ['#url'].options['attributes'] which solved our issue.

    Thank you!

  • Status changed to Closed: works as designed 9 months ago
  • 🇺🇸United States cdupree
Production build 0.71.5 2024