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

Allow per-bundle overrides of field definitions

$
0
0

Updated: Comment #N

Problem/Motivation

Right now, entity fields can optionally only exist on certain bundles but the same fields can not differ between bundles. Configurable field instances can have different settings per bundle and base fields can be different as well, for example the node title label can be configured per node type.

Due to that, Field API currently has a few workarounds that involve manually creating entity objects, which is very slow and a large performance problem.

Proposed resolution

Standardized terminology: base fields are all entity fields that exist independently of the bundle.

Unify and extend Entity::baseFieldDefinitions() and hook_entity_field_info() with by bundle variants:

Entity class methods
Changed: $EntityClass::baseFieldDefinitions($entity_type_id) to $EntityClass::baseFieldDefinitions(EntityTypeInterface $entity_type)
New: $EntityClass::fieldDefinitionsByBundle(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)

Hooks
Renamed: hook_entity_field_info($entity_type) to hook_entity_base_field_info(EntityTypeInterface $entity_type)
Renamed: hook_entity_field_info_alter(&$info, $entity_type) to hook_entity_base_field_info(&$base_field_definitions, EntityTypeInterface $entity_type)

New: hook_entity_field_info_by_bundle(EntityTypeInterface $entity_type, $bundle, $base_field_definitions)
New: hook_entity_field_info_by_bundle_alter(&$field_definitions, EntityTypeInterface $entity_type, $bundle)

The bundle for EntityManager::getFieldDefinitions($entity_type_id, $bundle) is now mandatory. EntityManager::getBaseFieldDefinitions($entity_type_id) has been added to allow to to fetch the base field definitions. This makes it clear that the common use case is to specify the entity type and bundle.

Additionally, the patch implements this for the node title field, which allows to remove the currently existing overrides and various simplification and improvements in multiple places.

Remaining tasks

User interface changes

API changes

Original report by @effulgentsia

EntityManager::getFieldDefinitions() allows for optional fields per bundle, but doesn't allow for a field of the same name to have different definitions per bundle. However, we need to allow for node titles to have potentially different labels per node type, and likely other use cases as well.

https://docs.google.com/document/d/1A5BLd-KmrLnJW88SdLX5HG3Xm7AyinxwXNAG... has notes from Prague about this.


Viewing all articles
Browse latest Browse all 298850

Latest Images

Trending Articles



Latest Images

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