Schema incorrect for config entity types with multi-part IDs (field_storage_config, field_config, entity_view_mode, entity_form_mode, entity_view_display and entity_form_display)

Created on 1 December 2022, over 2 years ago
Updated 13 May 2025, about 1 month ago

Problem/Motivation

\Drupal\field\Entity\FieldStorageConfig::id():

  public function id() {
    return $this->getTargetEntityTypeId() . '.' . $this->getName();
  }

and \Drupal\field\Entity\FieldStorageConfig::loadByName():

  public static function loadByName($entity_type_id, $field_name) {
    return \Drupal::entityTypeManager()->getStorage('field_storage_config')->load($entity_type_id . '.' . $field_name);
  }

and worse:
\Drupal\Core\Field\FieldConfigBase::id():

  public function id() {
    return $this->entity_type . '.' . $this->bundle . '.' . $this->field_name;
  }

and \Drupal\field\Entity\FieldConfig::loadByName():

  public static function loadByName($entity_type_id, $bundle, $field_name) {
    return \Drupal::entityTypeManager()->getStorage('field_config')->load($entity_type_id . '.' . $bundle . '.' . $field_name);
  }

(Same thing for \Drupal\Core\Field\Entity\BaseFieldOverride::loadByName(): 3 parameters that together create the name/ID.)

The corresponding config entity type annotations do not have any metadata at all that would allow us to construct these IDs automatically. They contain a config_prefix key-value pair, but not something like a config_name_parts key-value pair.

Until Drupal core provides an API for this, we have no choice but to hardcode these three. We can find them by searching for .*.* in *.schema.yml files.

But … that's how we can discover there's actually several more: core.entity_view_mode.*.*, core.entity_form_mode.*.*, core.entity_view_display.*.*.* and core.entity_form_display.*.*.*. For these, all of the mapping/loading logic is embedded in \Drupal\Core\Entity\EntityDisplayRepository.

Steps to reproduce

Proposed resolution

Harden \Drupal\jsonapi_schema\StaticDataDefinitionExtractor::extractConfigEntityType().

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024