Use the standard entity handler pattern

Created on 17 July 2024, over 1 year ago

Problem/Motivation

Registration uses this pattern:

$handler = $this->entityTypeManager->getHandler('registration', 'host_entity');
$host_entity = $handler->createHostEntity($entity);

This means there is only ever one host_entity handler, that defined for the registration entity type.

It should use this pattern:

$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'registration_host');
$host_entity = $handler->createHostEntity($entity);

This would allow sites to define different handlers (and thuse host entity wrappers) for different entity types. Which is the whole point of using a handler AFAIK.

Additionally, by namespacing the handler id as registration_host we prevent collision with a module that has its own idea of host entity.

Steps to reproduce

Handlers are documented here:
https://www.drupal.org/docs/drupal-apis/entity-api/handlers β†’

The method signature is:

     * @param string $entity_type_id
     *   The entity type ID for this handler.
     * @param string $handler_type
     *   The handler type to create an instance for.
     *
     * @return object
     *   A handler instance.
     *
     * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
     */
    public function getHandler($entity_type_id, $handler_type);

Proposed resolution

1. Create a LegacyRegistrationHostEntityHandler class that extends RegistrationHostEntityHandler, and trigger a deprecation error when this class is used. Define this class as the handler in the registration entity annotation.

2. Use hook_entity_type_build to set RegistrationHostEntityHandler as the default registration_host handler on all entity types.

3. Update all handler uses to use the new pattern.

Remaining tasks

User interface changes

None.

API changes

Using the provided handler for the registration entity type is deprecated.

Data model changes

None.

πŸ“Œ Task
Status

Active

Version

3.1

Component

Registration Core

Created by

πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

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