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.
Comments
Comment #2
ekes commentedAmusingly 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?
Comment #3
joachim commented> 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.
Comment #4
ekes commentedAh! 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.
Comment #5
joachim commented> 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
Comment #7
ekes commentedSeems 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...