Implements hook_entity_bundle_field_info_alter().
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');
}
}