WorkbenchAccessControlDeriver.php in Entity Reference Hierarchy 8.2
File
modules/entity_hierarchy_workbench_access/src/Plugin/Derivative/WorkbenchAccessControlDeriver.php
View source
<?php
namespace Drupal\entity_hierarchy_workbench_access\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WorkbenchAccessControlDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
protected $basePluginId;
protected $entityTypeManager;
protected $entityFieldManager;
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation, EntityFieldManagerInterface $entityFieldManager) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
$this->basePluginId = $base_plugin_id;
$this->entityFieldManager = $entityFieldManager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'), $container
->get('string_translation'), $container
->get('entity_field.manager'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->entityFieldManager
->getFieldMapByFieldType('entity_reference_hierarchy') as $entity_type_id => $fields) {
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
foreach ($fields as $field_name => $bundles) {
$this->derivatives["{$entity_type_id}__{$field_name}"] = [
'label' => $this
->t('@entity_type (@field)', [
'@entity_type' => $entity_type
->getLabel(),
'@field' => $field_name,
]),
'base_entity' => $entity_type
->getBundleEntityType() ?: $entity_type_id,
'entity' => $entity_type_id,
'field_name' => $field_name,
] + $base_plugin_definition;
}
}
return $this->derivatives;
}
}