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

Entity system does not provide an API for correctly loading an entity that is safe for editing

$
0
0

Problem/Motivation

When presenting an entity for interaction by a content author, many factors are considered:

  • What is the entity type?
  • What is the entity ID?
  • What is the revision?
  • What is the language?
  • Other things?

Some of these things are codified in places like \Drupal\Core\ParamConverter\EntityConverter
But that is not an API that is reusable.

Additionally, the current best practice for retrieving an entity is:

$entity = $this->entityTypeManager->getStorage($entity_type_id)->load($entity_id);

Yet this bypasses all access, revision checking, translation handling, etc.

Core provides a service for loading entities: \Drupal\Core\Entity\EntityRepository
But it only provides other helper methods for edge cases, not the 80% case.

Proposed resolution

Expand \Drupal\Core\Entity\EntityRepository to include methods for:

  • retrieving the raw entity (equivalent of getStorage()->load())
  • retrieving a version of the entity suitable for editing (latest revision? correct language?)

Switch the static Entity::load() to use the correct one instead of it manually introspecting the storage.

Remaining tasks

User interface changes

API changes

Data model changes


Viewing all articles
Browse latest Browse all 296179

Trending Articles



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