W3cubDocs

/Drupal 8

function field_entity_bundle_field_info

field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)

Implements hook_entity_bundle_field_info().

Related topics

Field API
Attaches custom data fields to Drupal entities.

File

core/modules/field/field.module, line 193
Attach custom data fields to Drupal entities.

Code

function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
  if (\Drupal::entityManager()->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 = array();
    foreach ($field_configs as $field_instance) {
      $result[$field_instance->getName()] = $field_instance;
    }

    return $result;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!field!field.module/function/field_entity_bundle_field_info/8.1.x