Problem/Motivation
Error when I'm trying to add a new field in the event instance entity.
Using Drupal 10.3.6 and also in an empty Drupal installation 10.1.8
Steps to reproduce
- Install the recurring_events module 2.0.2
- Go to /admin/structure/events/instance/types/eventinstance_type/default/edit/fields
- Add a new field referenced field, like taxonomy or content.
- In reference type checkboxes check one of the options.
You should see an ajax error
Also, if you go recent log log messages: an message like: Error: Call to a member function hasTranslation() on null in Drupal\recurring_events\Entity\EventInstance->getEventSeries() (line 368 of /var/www/web/modules/contrib/recurring_events/src/Entity/EventInstance.php). should appear.
You can see the error in the image below:

Proposed resolution
In the following computed fields:
- WaitlistCount
- AvailabilityCount
- RegistrationCount
Add the field_ui.field_add_eventinstance route as the excluded route in the $excluded_routes variable.
Like:
$excluded_routes = [
'entity.eventseries.add_instance_form',
'field_ui.field_add_eventinstance',
];
Remaining tasks
Test with other referenced entities since the route name could differ from the new ones added.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | chrome-capture-2024-10-4.gif | 3.62 MB | joaopauloc.dev |
| #3 | adding-field-without-error.gif | 7.42 MB | joaopauloc.dev |
| issue-adding-reference-field-event-instance.gif | 16.53 MB | joaopauloc.dev |
Issue fork recurring_events-3483283
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 #3
joaopauloc.dev commentedHi folks.
First of all, great module!!! good job.
This module saves me a lot of time.
With the fixed applied I was able to add the fields as expected.
Take a look at the image below.
Comment #4
pfrenssenThanks for the report! I can replicate the error.
However it is not the right solution to start maintaining a potentially unlimited list of routes that might at some point in the future decide to compute the availability on a new or orphaned event instance.
What is the root of the problem is that the registration creation service expects a fully populated event instance (including referenced event series):
We should here throw an
\InvalidArgumentExceptionif an event instance is passed that is missing an event series. And on the calling side we should probably avoid calling into::setEventInstance()if the entity is new.Comment #6
pfrenssenI added a new MR with my proposed fix. @joaopauloc.dev does this also solve the problem for you?
Comment #7
joaopauloc.dev commentedhey @pfrenssen.

I agree with you regarding the route stuff.
I tested your merge request, and it works.
Thanks.
Comment #9
pfrenssenThanks very much for the report and the review!