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

  1. Install the recurring_events module 2.0.2
  2. Go to /admin/structure/events/instance/types/eventinstance_type/default/edit/fields
  3. Add a new field referenced field, like taxonomy or content.
  4. 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:
Issue example

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.

Command icon 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

joaopauloc.dev created an issue. See original summary.

joaopauloc.dev’s picture

Issue summary: View changes
Status: Active » Needs work
StatusFileSize
new7.42 MB

Hi 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.

adding fields

pfrenssen’s picture

Thanks 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):

  /**
   * Set the event entities.
   *
   * @param \Drupal\recurring_events\Entity\EventInstance $event_instance
   *   The event instance.
   */
  public function setEventInstance(EventInstance $event_instance) {
    $this->eventInstance = $event_instance;
    $this->eventSeries = $event_instance->getEventSeries();
  }

We should here throw an \InvalidArgumentException if 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.

pfrenssen’s picture

Version: 2.0.2 » 2.0.x-dev
Priority: Major » Normal
Status: Needs work » Needs review

I added a new MR with my proposed fix. @joaopauloc.dev does this also solve the problem for you?

joaopauloc.dev’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.62 MB

hey @pfrenssen.
I agree with you regarding the route stuff.
I tested your merge request, and it works.
Thanks.
test new merge request

  • pfrenssen committed 400e300b on 2.0.x
    Issue #3483283 by joaopauloc.dev, pfrenssen: Unexpected error when...
pfrenssen’s picture

Status: Reviewed & tested by the community » Fixed

Thanks very much for the report and the review!

  • pfrenssen committed 400e300b on 3.0.x
    Issue #3483283 by joaopauloc.dev, pfrenssen: Unexpected error when...

Status: Fixed » Closed (fixed)

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