function ctools_entity_mask_entity_bundle_field_info

Same name in other branches
  1. 8.x-3.x modules/ctools_entity_mask/ctools_entity_mask.module \ctools_entity_mask_entity_bundle_field_info()

Implements hook_entity_bundle_field_info().

File

modules/ctools_entity_mask/ctools_entity_mask.module, line 140

Code

function ctools_entity_mask_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle) {
    $info = [];
    $mask = $entity_type->get('mask');
    // Nothing to do if the entity type is not masking another entity type.
    if (empty($mask)) {
        return $info;
    }
    $storage_info = ctools_entity_mask_entity_field_storage_info($entity_type);
    
    /** @var \Drupal\field\FieldConfigInterface[] $fields */
    $fields = \Drupal::entityTypeManager()->getStorage('field_config')
        ->loadByProperties([
        'entity_type' => $mask,
        'bundle' => $bundle,
    ]);
    foreach ($fields as $field) {
        $field_name = $field->getName();
        $info[$field_name] = $field->createDuplicate()
            ->set('entity_type', $mask)
            ->set('fieldStorage', $storage_info[$field_name]);
    }
    return $info;
}