1

When creating a config entity, we get an example_entity.schema.yml file:

example_module.example_entity.*:
  type: config_entity
  label: 'Example config'
  mapping:
    id:
      type: string
      label: 'ID'
    label:
      type: label
      label: 'Label'
    uuid:
      type: string

Creating entities of this type will result in config names, where the asterisk is replaced with the "id" property of the entity:

example_module.example_entity.name_1
example_module.example_entity.name_2
...

But how to control, which property is used and how to add support for more properties? For example, in core's core.entity_form_display.*.*.*, what is mapping the entity type to first wildcard, the entity bundle to second and the display mode to third?

1 Answer 1

1

The remainder of the config name is by definition the ID:

core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php

 * Configuration object names of configuration entities are comprised of two
 * parts, separated by a dot:
 * - config_prefix: A string denoting the owner (module/extension) of the
 *   configuration object, followed by arbitrary other namespace identifiers
 *   that are declared by the owning extension; e.g., 'node.type'. The
 *   config_prefix does NOT contain a trailing dot. It is defined by the entity
 *   type's annotation.
 * - ID: A string denoting the entity ID within the entity type namespace; e.g.,
 *   'article'. Entity IDs may contain dots/periods. The entire remaining string
 *   after the config_prefix in a config name forms the entity ID. Additional or
 *   custom suffixes are not possible.

However, it is possible for the config entity class to override id() with a computed compound ID. Like in the example you've mentioned:

core/lib/Drupal/Core/Entity/EntityDisplayBase.php

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.