occurrence page crashes if there are more than one occurrence field on an entity type

Created on 13 March 2024, 10 months ago
Updated 29 March 2024, 10 months ago

Problem/Motivation

I installed the example module, and then tried to make my own event type from scratch.

The occurence page e.g. node/10/date_occur/2024-04-13T11%3A29%3A38Z--2024-04-13T11%3A30%3A38Z crashes with:

> Error: Call to a member function getSetting() on null in Drupal\date_occur_ui\Routing\ParamConverter->convert() (line 82 of modules/contrib/date_occur/date_occur_ui/src/Routing/ParamConverter.php).

This is because it's trying to work with the wrong field. And that's because Drupal\date_occur_ui\Routing\RouteSubscriber takes into account that there may be multiple fields, but registers the same path for multiple routes: in my router table I have:

- date_occur_ui.node.doe_occurrence.view /node/{node}/date_occur/{date_occur}
- date_occur_ui.node.field_localgov_event_occurrence.view /node/{node}/date_occur/{date_occur}

With the same path, only the first route will get matched for the path.

I can see two ways to fix this:

- A. Add the $field_id to the path.
- B. Only make one route, and instead, the ParamConverter will need to figure out which field to use based on the bundle of the entity.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

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

    Amusingly I think I did have the $field_id in the path at some point and refactored it out to simplify things. I think there might be other complexities involved with having multiple fields on the same entity. Is there a particular use use case for having more than on?

  • 🇬🇧United Kingdom joachim

    > Is there a particular use use case for having more than on?

    I installed the demo module and wanted to build my own event node type while referring back to the demo.

    Would one field storage work across multiple node types if different settings for the date are required? I can't remember offhand whether the settings are on the storage or the field instance.

  • 🇳🇱Netherlands ekes

    Ah! I thought you meant more than one field on the same entity type.

    I'll look back at the original repo where I removed the field name from the path see what comment I made, and see if it makes sense to put it back for working out the field to load.

  • 🇬🇧United Kingdom joachim

    > Ah! I thought you meant more than one field on the same entity type.

    Yup, that's what I meant.

    - The demo module provides the occurrence field A on its own node type
    - I made node type my_event with occurrence field B

    • ekes committed 26b531bf on 0.1.x
      Issue #3427637: Fix multiple occurrence field paths.
      
      Initial version...
  • Status changed to Fixed 10 months ago
  • 🇳🇱Netherlands ekes

    Seems in moving the field storage id into the route parameters I'd not taking into account it was creating multiple routes (with different param values) but the same path. So opting (almost) for A putting back just the field machine name into the URL fixes this https://git.drupalcode.org/project/date_occur/-/commit/26b531bf11cb13bed...

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

Production build 0.71.5 2024