public function EntityHierarchy::buildConfigurationForm in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 modules/entity_hierarchy_workbench_access/src/Plugin/AccessControlHierarchy/EntityHierarchy.php \Drupal\entity_hierarchy_workbench_access\Plugin\AccessControlHierarchy\EntityHierarchy::buildConfigurationForm()
File
- modules/
entity_hierarchy_workbench_access/ src/ Plugin/ AccessControlHierarchy/ EntityHierarchy.php, line 297
Class
- EntityHierarchy
- Defines a hierarchy based on an entity hierarchy field.
Namespace
Drupal\entity_hierarchy_workbench_access\Plugin\AccessControlHierarchyCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$entity_type_id = $this->pluginDefinition['entity'];
$booleans = $this->entityFieldManager
->getFieldMapByFieldType('boolean');
$options = [];
if (isset($booleans[$entity_type_id])) {
foreach ($booleans[$entity_type_id] as $field_name => $info) {
$sample_bundle = reset($info['bundles']);
$fields = $this->entityFieldManager
->getFieldDefinitions($entity_type_id, $sample_bundle);
$options[$field_name] = $fields[$field_name]
->getLabel();
}
}
$form['boolean_fields'] = [
'#title' => new TranslatableMarkup('Editorial section flag'),
'#description' => new TranslatableMarkup('Select the field to use to enable the entity as an editorial section. Not all entities in the tree need to be editorial sections.'),
'#options' => $options,
'#type' => 'checkboxes',
'#default_value' => $this->configuration['boolean_fields'],
];
$entityType = $this->entityTypeManager
->getDefinition($entity_type_id);
if ($bundle = $entityType
->getBundleEntityType()) {
$bundleEntityType = $this->entityTypeManager
->getDefinition($bundle);
$form['bundles'] = [
'#title' => $bundleEntityType
->getPluralLabel(),
'#description' => new TranslatableMarkup('Select the @label this access scheme applies to.', [
'@label' => $bundleEntityType
->getPluralLabel(),
]),
'#type' => 'checkboxes',
'#options' => array_map(function (EntityInterface $entity) {
return $entity
->label();
}, $this->entityTypeManager
->getStorage($bundle)
->loadMultiple()),
'#default_value' => $this->configuration['bundles'],
];
}
return $form;
}