Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FieldHooks.php

function FieldHooks::entityBundleFieldInfo

Implements hook_entity_bundle_field_info().

File

core/modules/field/src/Hook/FieldHooks.php, line 192

Class

FieldHooks
Hook implementations for field.

Namespace

Drupal\field\Hook

Code

public function entityBundleFieldInfo(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
    if (\Drupal::entityTypeManager()->getStorage($entity_type->id()) instanceof DynamicallyFieldableEntityStorageInterface) {
        // Query by filtering on the ID as this is more efficient than filtering
        // on the entity_type property directly.
        $ids = \Drupal::entityQuery('field_config')->condition('id', $entity_type->id() . '.' . $bundle . '.', 'STARTS_WITH')
            ->execute();
        // Fetch all fields and key them by field name.
        $field_configs = FieldConfig::loadMultiple($ids);
        $result = [];
        foreach ($field_configs as $field_instance) {
            $result[$field_instance->getName()] = $field_instance;
        }
        return $result;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal