If you are attaching some option attributes to a link field (using a custom module for example), those attributes are removed on node save.
One solution is to use link_attributes, but you might not want to allow users to edit those attributes from node edit.
LinkWidget::formElement()
puts the options attributes into $element['attributes']
, which is a value
type element. Upon submitting, LinkWidget::massageFormValues()
does not use this value. It is effectively discarded.
Since there's no form element for the attributes in the LinkWidget
the easiest way to reproduce the issue is by using Drush.
drush eval '$node = \Drupal\node\Entity\Node::load(NID);$node->FIELD_MACHINE_NAME->options = ["attributes" => ["class" => "test-class"]];$node->save();'
drush eval '$node = \Drupal\node\Entity\Node::load(NID);var_dump($node->FIELD_MACHINE_NAME->options);'
Expected result:
The options should be the same as when you loaded them in step 4, which should look like this:
array(1) {
["attributes"]=>
array(2) {
["class"]=>
string(17) "test-class-edited"
}
}
Actual result:
The options array is empty:
array(0) {
}
Update LinkWidget::massageFormValues()
to merge in the submitted attributes. This is tricky to do in a backward-compatible way, maybe impossible. A previous attempt to solve the issue by changing the element structure in the form broke a few modules that deal with link attributes. It may be impossible to fix this issue in a way that is backward compatible for all contrib modules.
Needs work
11.0 🔥
link.module
A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.
The major change should have a special release note written to summarize the importance of the change. See Write a release note for an issue.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.