Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291715

EntityFieldDefinitionTrait::getEntityTypeId() prevents reuse of ContentEntity class outside of derived plugins

$
0
0

Problem/Motivation

EntityFieldDefinitionTrait::getEntityTypeId() assumes that it is in a plugin whose ID is of the form 'foo:ENTITY_TYPE'.

This means that if you want to use ContentEntity as a base class for a custom source plugin, getEntityTypeId() fails to find the entity type.

The function is redundant, at least within ContentEntity's use of the trait, because ContentEntity does this in __construct():

    $this->entityType = $this->entityTypeManager->getDefinition($plugin_definition['entity_type']);

so the entity type and its ID are always available.

A workaround is to override the trait's method like this:

  /**
   * {@inheritdoc}
   */
  protected static function getEntityTypeId($plugin_id) {
    // Override this so it doesn't try to get the entity type ID from the plugin
    // ID, which will fail.
    return 'my_entity_type';
  }

but this violates DRY.

Steps to reproduce

Proposed resolution

Remove the method and get the entity type ID from $this->entityType->id().

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 291715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>