Getting the current entity from the route match is brittle

Created on 13 March 2024, 4 months ago
Updated 15 March 2024, 4 months ago

Problem/Motivation

    if ($entity = \Drupal::routeMatch()->getParameter($entity_type_id)) {

This isn't going work properly if you have a path like /parent_entity-type/PARENT-ID/child-entity-type/CHILD-ID and you have occur fields on both entity types.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • πŸ‡³πŸ‡±Netherlands ekes

    Assuming this is in the section that renames the local tasks which is the reason for the comment https://git.drupalcode.org/project/date_occur/-/blob/0.1.x/date_occur_ui... It's also partly the reason all that code is separate in the _ui module. It should fail gracefully however, and not explode. So the fixes there have been helpful. Not changing the local tasks names in this case isn't essential.

    That said the parameter bag that it is being retrieved from is stored key => value, it seems convention that the parameter of the primary entity on the route will be keyed with the entity_type_id, and so far I've not seen an example for an entity route implementation that will fail on this. If there is one maybe can look to see if it can be made more robust.

Production build 0.69.0 2024