Problem/Motivation

Text formats can convert text into links. Entity usage needs to account for what the user sees not the raw field value.

Steps to reproduce

Add add text into a text field that uses a formatter that automatically converts links to URLs and link is an absolute link to an entity on your site.

Proposed resolution

If the text field's filter format has filter_url enabled then we should convert text into links before looking for links in \Drupal\entity_usage\Plugin\EntityUsage\Track\HtmlLink

Remaining tasks

User interface changes

API changes

Data model changes

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

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs work

Now to add test coverage...

alexpott’s picture

I've been thinking about this issue and it makes me wonder if we should be maintaining:

  • \Drupal\entity_usage\Plugin\EntityUsage\Track\EntityEmbed
  • \Drupal\entity_usage\Plugin\EntityUsage\Track\HtmlLink
  • \Drupal\entity_usage\Plugin\EntityUsage\Track\MediaEmbed
  • \Drupal\entity_usage\Plugin\EntityUsage\Track\LinkIt
  • \Drupal\entity_usage\Plugin\EntityUsage\Track\CkeditorImage

I think we should have a single text field plugin that uses the processed text (and summary if available) to determine usage. The plugin should support entity usage discovery from both the URL and the data-entity-uuid and data-entity-type attributes.

This approach would have the following advantages:

  • No multiple dom parsing from LinkIt/ EntityEmbed / CkEditorImage / MediaEmbed - these plugins are all essentially the same - they use the attributes to determine if there is a link
  • A single plugin working through all the links is more performant and less code to maintain
  • Support for any esoteric filter that adds links in a way not covered by the existing plugins
alexpott’s picture

@marcosano has pointed out that entity embed is a problem. Entity embed possibly will add links to other entities and we wouldn't want these usages registered as part of the entity with text field... so yeah #4 is wrong-headed.

That said I think it points to the fact that we could reorganise the plugin relationships so we only have to create the dom for each text field once.

alexpott’s picture

Title: Entity usage should use the processed text value and not the raw text value » \Drupal\entity_usage\Plugin\EntityUsage\Track\HtmlLink should use respect the FilterUrl setting when looking for links in text
Issue summary: View changes
marcoscano’s picture

@alexpott I am happy with the MR, but see the status is still NW. Did you want to include anything else or is this ready to go?
Thanks!

alexpott’s picture

Status: Needs work » Needs review

I think this is ready to go.

  • marcoscano committed b5908713 on 8.x-2.x authored by alexpott
    Issue #3516678 by alexpott, marcoscano: \Drupal\entity_usage\Plugin\...
marcoscano’s picture

Status: Needs review » Fixed

Great, thanks! 🙏

marcoscano’s picture

Just tagged a new release with this and a couple other bug fixes.

Status: Fixed » Closed (fixed)

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