function paragraphs_library_entity_bundle_field_info_alter

Implements hook_entity_bundle_field_info_alter().

File

paragraphs/modules/paragraphs_library/paragraphs_library.module, line 273
Main module file for the Paragraphs Library module.

Code

function paragraphs_library_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {

  // Ensure that Paragraph fields that only allow certain Paragraphs types
  // cannot have this restriction bypassed by the use of library items.

  /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
  foreach ($fields as $name => $definition) {
    if ($definition
      ->getType() != 'entity_reference_revisions') {
      continue;
    }
    if ($definition
      ->getSetting('target_type') != 'paragraph') {
      continue;
    }
    $fields[$name]
      ->addConstraint('ParagraphsLibraryItemHasAllowedParagraphsType');
  }
}