Problem/Motivation
Having an entity context available makes it easier to access the "current" entity for context aware plugins: https://www.drupal.org/docs/drupal-apis/plugin-api/plugin-contexts
This effectively prevents duplication of the code that checks and loads an entity from route parameters. A practical example of this would be creating a block that is only displayed when a log
entity is provided in the current page context.
Drupal core provides a context provider for both node and taxonomy term routes:
- https://git.drupalcode.org/project/drupal/-/blob/9.4.x/core/modules/node...
- https://git.drupalcode.org/project/drupal/-/blob/9.4.x/core/modules/taxo...
There has been talk of making these core implementations more generic and be provided for all entity types (I saw @pcambra suggest this somewhere but can't find it now). I think this is a good idea in the long run but lets implement one ourselves now.
Related issues:
- #3210666: Add a base class, or possibly deriver for entity route contexts
- #3138465: Add a generic entity route context
Steps to reproduce
N/A
Proposed resolution
Mimic the drupal core node/term route context.
Remaining tasks
Implement.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork log-3261662
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
paul121 CreditAttribution: paul121 commentedAdding related core issues
Comment #4
paul121 CreditAttribution: paul121 commentedComment #5
m.stentaThis looks good to me - thanks @paul121!
Comment #7
m.stenta