function entity_hierarchy_workbench_access_entity_bundle_field_info_alter in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x modules/entity_hierarchy_workbench_access/entity_hierarchy_workbench_access.module \entity_hierarchy_workbench_access_entity_bundle_field_info_alter()
Implements hook_entity_bundle_field_info_alter().
File
- modules/
entity_hierarchy_workbench_access/ entity_hierarchy_workbench_access.module, line 15 - Main module functions.
Code
function entity_hierarchy_workbench_access_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
$schemes = array_filter(\Drupal::entityTypeManager()
->getStorage('access_scheme')
->loadMultiple(), function (AccessSchemeInterface $scheme) {
return strpos($scheme
->getAccessScheme()
->getPluginId(), 'entity_hierarchy') === 0;
});
/** @var \Drupal\workbench_access\Entity\AccessSchemeInterface $scheme */
foreach ($schemes as $scheme) {
$accessPlugin = $scheme
->getAccessScheme();
$definition = $accessPlugin
->getPluginDefinition();
if ($entity_type
->id() !== $definition['entity']) {
continue;
}
$configuration = $accessPlugin
->getConfiguration();
if (!in_array($bundle, $configuration['bundles'], TRUE)) {
continue;
}
if (!isset($fields[$definition['field_name']])) {
continue;
}
$fields[$definition['field_name']]
->addConstraint('ValidHierarchySection');
}
}