Invalid label field definition in Event Instance entity type

Created on 24 June 2024, 6 months ago

Problem/Motivation

The entity type annotation in the src/Entity/EventInstance.php contains a label key in the entity_keys property:

/*
 * ...
 *   entity_keys = {
 *     "id" = "id",
 *     "revision" = "vid",
 *     "published" = "status",
 *     "langcode" = "langcode",
 *     "uuid" = "uuid",
 *     "label" = "title",
 *     "bundle" = "type",
 *     "uid" = "uid",
 *   },
 * ...
 */

However, the title field does not exist in base field definitions. As a result, the \Drupal\Core\Entity\ContentEntityBase::label method fails with the following error:

Error: Call to a member function getFieldStorageDefinition() on null in Drupal\Core\Entity\ContentEntityBase->getEntityKey() (line 1343 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Steps to reproduce

The issue happens if the label() method is called; the easiest way to reproduce the issue is to install the Gin Toolbar module (which tries to render the label of the entity being viewed) and open the Event Instance page.

Below are steps to reproduce (on fresh D10):

1. Install Gin, Gin Toolbar, and Recurring Events.
2. Enable Gin as the default administration theme.
3. Enable Gin Toolbar and Recurring Events modules.
4. Create a new Event (make sure there's at least one Event Instance).
5. Open the Event Instance page (e.g. /event/1).

Expected: the page opens.
Actual: the error is displayed:

The website encountered an unexpected error. Try again later.

Error: Call to a member function getFieldStorageDefinition() on null in Drupal\Core\Entity\ContentEntityBase->getEntityKey() (line 1343 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->label() (Line: 242)
gin_toolbar_preprocess_toolbar()
...

The issue is not specific to Gin Toolbar, it's just an easy way to reproduce it (and that's where we faced it).

Proposed resolution

1. Remove the label property from entity_keys.
2. Override the label() method to return the title of the parent Event Series entity.
3. Add an update hook to re-install the eventinstance entity type definition.
4. Add a test for the label() method (it should fail with the current code).

Remaining tasks

TBD

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

2.0

Component

Recurring Events (Main module)

Created by

πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024