Problem/Motivation

URL substitution plugins were introduced with #2786049: Make entity URL substitutions pluggable to support a wider variety of use cases..

The current substitution plugins have a plugin annotation that states which entity types a single plugin can handle.
This is too ambiguous and allows some plugins to be used with an entity type they don't support.

The file for entity example doesn't have a canonical link defined in the link template, but it is still possible to select the canonical substitution plugin.

Proposed resolution

Add a method to all substitution plugins that takes an argument of EntityTypeInterface. The plugin would then be able to use the entity type, and check if a certain link template exists, and/or check the type itself.

Remaining tasks

  • Find solution
  • Add automated test
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anon created an issue. See original summary.

Sam152’s picture

Yeah, I see what you mean. There are a few ways we could deal with this that I've thought about:

  1. Use a method like isApplicable as you suggest.
  2. Add a key to the annotation to exclude some entity types (still only fixes file entity, there could be others).
  3. Add keys to the canonical annotation, to specify some basic entity types like node, term etc.

I think the method is the most flexible and will work for the most use-cases.

anon’s picture

So a method it is. I like your method name proposal isApplicable so lets call it that.

Whats still unclear is what type of argument it should take. I guess the easiest is to send the entity type id, like in the other method, and then load the Entity type from that in the SubstitutionManager.

For that we need to inject a EntityTypeManager I guess in the SubstitutionManager.

Any thoughts on this?

anon’s picture

Assigned: Unassigned » anon
anon’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
11.48 KB
anon’s picture

FileSize
1.16 KB
11.48 KB

Fixed some coding standards.

Sam152’s picture

Status: Needs review » Reviewed & tested by the community

This looks fantastic.

anon’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
9.1 KB
18.08 KB

I found that there were some problems with the patch in #6.

When adding a file matcher to a profile, the default plugin would be set to canonical. The fix was to change the order of the arrays in the defaultConfiguration() and let the default value to be overwritten by the one defined in the file matcher plugin.

Also, the tests would fail as a part of the fix above. That is also fixed in this new patch.

I also remove the filterPlugins() method from the SubstitutionManagerInterface as that method does not need to be in the interface. Now its a protected method in the SubstitutionManager instead.

I would like this to be reviewed again before committing.

  • anon committed 0bded5f on 8.x-5.x
    Issue #2789021 by anon: URL substitutions plugins are too ambiguous
    
anon’s picture

Status: Needs review » Fixed
Sam152’s picture

Belated reply, but looks good. Thanks for getting this in.

Status: Fixed » Closed (fixed)

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