Unable to reference event instances

Created on 23 April 2024, 8 months ago

Problem/Motivation

You may want to create an entity reference field which references event instances. However this is not possible as event instances do not have an actual title field. Instead they rely on a title field from the parent recurring events using field inheritance. This does not work with the Core entity reference field.

As a workaround it is possible to create a dummy title field on event instances but it does not seem like a solid solution going forward. I do not know if this should be solved by Drupal Core (by adding support for referencing entities without title fields), by Field Inheritance module (by improving the handling of inherited fields) or by the Recurring Events module (by adding a solution which works in this instance).

Steps to reproduce

- Install a site with the Recurring Events module on SimplyTest.me
- Create an new field on a content type
- Choose Reference / Other
- Choose "Event Instance entity" as the type of item to reference and "Default" as the Event instance type.
- Save settings
- Go to the create form for the content type
- Open developer tools
- Start typing in the new entity reference field
- See that autocomplete starts
- See that requests to retrieve autocomplete results fail with response code 500
- Go to the recent log messages
- See that it contains PHP errors "Drupal\Core\Entity\Query\QueryException: 'title' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 369 of /var/lib/tugboat/stm/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php)."

Using a Views as an entity reference method does not fix the problem.

Proposed resolution

?

Remaining tasks

?

User interface changes

?

API changes

?

?

Data model changes

✨ Feature request
Status

Active

Version

2.0

Component

Recurring Events (Main module)

Created by

πŸ‡©πŸ‡°Denmark kasperg

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

Comments & Activities

  • Issue created by @kasperg
  • Assigned to praveen rani
  • πŸ‡©πŸ‡°Denmark ras-ben Copenhagen

    A (very ugly) work around, that i added in a custom updatehook:

      $entity_type = 'eventinstance';
    
      $field_storage_definition = BaseFieldDefinition::create('string')
        ->setName('title')
        ->setLabel(t('Mock-title field'))
        ->setDescription(t('This is a mock title field, unused and read only. It is required, for eventinstances to work with entity reference autocomplete fields.'))
        ->setReadOnly(TRUE)
        ->setRevisionable(FALSE);
    
      \Drupal::entityDefinitionUpdateManager()
        ->installFieldStorageDefinition('title', $entity_type, $entity_type, $field_storage_definition);
    
      return "Mock title field has been added to the $entity_type entity.";
    
  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States owenbush Denver, CO

    Yea this is a problem. There's a core issue around computed fields in entity queries: πŸ› Handle computed fields in entity queries: throwing a helpful exception is better than a PHP fatal error Needs work but the solution there is to just throw and handle an exception, that won't make this work.

    The workaround above worries me because I feel like it could break inheritance completely in certain circumstances. I may have to think on this one, maybe even to the point of creating a custom event instance reference field so we can control things better.

Production build 0.71.5 2024