Problem/motivation

Linkit widget, when setting data-entity-substitution hardcode the substitution based on the entity type
https://git.drupalcode.org/project/linkit/-/blob/7.x/src/Plugin/Field/Fi...

The bug is not visible when searching for an entity from node form because the value get updated by JS using the proper substitution defined in config.

Steps to reproduce

  1. Edit Media matcher
  2. Set Substitution Type to Direct URL to media file entity
  3. Configure a link field to use linkit widget
  4. Create a node and populate the link field with a media
  5. The generated link point to the actual file
  6. Edit the node and save without change
  7. The generated link point to /media/mid/edit

Proposed resolution

Linkit widget must load the substitution as by profile configuration, Hardcoded solution can be used as fallback

Issue fork linkit-3589257

Command icon 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

marco.pagliarulo created an issue. See original summary.

marco.pagliarulo’s picture

Patch for

mark_fullmer’s picture

Using the Linkit Profile configuration matchers' substitution_type, if present, makes sense. I just have a small optimization suggestion for the code. Can we avoid multiple instances of $entity->getEntityTypeId() === 'file' ? 'file' : 'canonical';? I think the code would execute the same if we just move $substitution_type = $entity->getEntityTypeId() === 'file' ? 'file' : 'canonical'; above if ($matcher) {, then remove the else fallback.

marco.pagliarulo’s picture

@mark_fullmer thanks for the reply. I refactored the code as you suggested moving

$substitution_type = $entity->getEntityTypeId() === 'file' ? 'file' : 'canonical'; 

above.

mark_fullmer’s picture

Status: Needs review » Fixed

Thanks for the refactoring! This looks good. Merging!

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

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

Maintainers, credit people who helped resolve this issue.