Problem/motivation
LinkitWidget::massageFormValues() re-adds the fragment and query to $attributes and then stores them with:
massageFormValues() stores the fragment and query with:
$value += ['options' => $attributes];
The += union only assigns options when it doesn't yet exist. If $value['options'] is already populated (a widget subclass, or link_attributes), this is a no-op and the fragment, query and data-entity-* attributes are dropped — undoing #3223919 (https://www.drupal.org/project/linkit/issues/3223919) / #3359375 (https://www.drupal.org/project/linkit/issues/3359375). Same defect as core #3056652 (https://www.drupal.org/node/3056652).
Only paths resolving to an existing entity are affected: those become entity:node/1 (fragment must go to options → dropped), while a non-resolving path stays internal:/node/1#foo and keeps the fragment inline.
Steps to reproduce
- A widget extending LinkitWidget that adds an element under options (or the linkit_attributes widget).
- Save a link to an existing entity with a fragment, e.g. /node/1#section-2.
- The stored options has no fragment.
Proposed resolution
Merge instead of a lossy union:
$value['options'] = $attributes + ($value['options'] ?? []);
Keeps entity:node/1, the fragment, and any pre-existing option (e.g. attributes.target).
AI disclosure: AI assisted with the investigation and local browser testing.
Issue fork linkit-3641259
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anneke_vde commentedComment #4
anneke_vde commentedOpened an MR against 7.x.
The fix AI assisted but I tested this locally.
Fix: merge instead of a lossy union:
Confirmed on 7.0.19: with pre-set options the fragment is dropped; after the fix the URI stays entity:node/1 and options keeps both the fragment and the existing attribute.
Comment #5
mark_fullmerThanks, @anneke_vde, for this report and the proposed fix -- and for mentioning the AI assist and the manual testing. The statement of the problem and the proposed resolution seem very straightforward on the surface. I'll just do a little double-checking and if everything looks good, I will merge it soon.