Exacte same issue as #2755403: Edit link don't remove data- attributes which seems to be reintroduced. Copy from the steps to reproduce from the original ticket:

When editing a link, the data- attributes will in some situations be kept in the old state.

Steps to reproduce:

Add an internal link to an entity (entity:node/1)
The data- attributes will be set
Edit that link, and set an external URL as href.
The data- attributes is the same as before.
This causes the linkit_filter to always override the href.

Expected behavior:

Add an internal link to an entity (entity:node/1)
The data- attributes will be set
Edit that link, and set an external URL as href.
The data- attributes removed.

Original commit that fixed this, which seems gone in current release and dev version: https://git.drupalcode.org/project/linkit/commit/cc3edc5

Attached is a patch that fixes it again.

Comments

weseze created an issue. See original summary.

rang501’s picture

This patch doesn't fix it, at least not my use case - adding link around entity embed elements will preserve data-* attributes if the link is external.
The logic inside the form submit handler seems weird - if the attribute value is empty then it tries to check if $link_element is empty, but it doesn't make sense because it is usually an array so this is most likely true. I'm assuming this is wrong and it should check attribute value inside of $link_element.

briantschu’s picture

Building on this, let's set the `$form_state` values to match what is in `$link_element` so the `data-*` attributes update.

Status: Needs review » Needs work

The last submitted patch, 3: linkit_rename-stale-data-attributes_3111578-3.patch, failed testing. View results

liam morland’s picture

Is there a reason it needs to use data attributes? Why not look at the href attribute. If it is an internal link like entity:node/1, convert it to the correct path for output. Otherwise, leave it unchanged.

Doing it this way would probably also fix #3222939: Do not require selection of autocomplete if only one match (pressing 'Submit' is sufficient).

mark_fullmer’s picture

Status: Needs work » Postponed (maintainer needs more info)

I believe this was resolved in #3443845: When [Enter] key is used to replace a link, the previous link's attributes are not removed. Marking as "Postponed (maintainer needs more info)" in case there is still a different issue here. If there is, updated steps to reproduce would be great. Thanks!

mark_fullmer’s picture

Version: 8.x-5.x-dev » 6.1.x-dev
mark_fullmer’s picture

Version: 6.1.x-dev » 7.x-dev
vastr’s picture

Patch for the 7.0.2.

weseze’s picture

Status: Postponed (maintainer needs more info) » Fixed

Retested this in version 7.0.9 and the patch is longer needed. Marking as fixed.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.