You are here

function ctools_entity_mask_entity_bundle_field_info in Chaos Tool Suite (ctools) 8.3

Implements hook_entity_bundle_field_info().

File

modules/ctools_entity_mask/ctools_entity_mask.module, line 140
Helps entity type to take the fields, display configuration from entity type.

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;
}