You are here

class WorkbenchAccessControlDeriver in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 modules/entity_hierarchy_workbench_access/src/Plugin/Derivative/WorkbenchAccessControlDeriver.php \Drupal\entity_hierarchy_workbench_access\Plugin\Derivative\WorkbenchAccessControlDeriver

Defines a class for deriving workbench access plugins for hierarchies.

Hierarchy

Expanded class hierarchy of WorkbenchAccessControlDeriver

File

modules/entity_hierarchy_workbench_access/src/Plugin/Derivative/WorkbenchAccessControlDeriver.php, line 16

Namespace

Drupal\entity_hierarchy_workbench_access\Plugin\Derivative
View source
class WorkbenchAccessControlDeriver extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The base plugin ID.
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Entity field manager.
   *
   * @var \Drupal\Core\Entity\EntityFieldManagerInterface
   */
  protected $entityFieldManager;

  /**
   * Creates the DynamicLocalTasks object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The translation manager.
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
   *   Entity field manager.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    foreach ($this->entityFieldManager
      ->getFieldMapByFieldType('entity_reference_hierarchy') as $entity_type_id => $fields) {

      /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
      $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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WorkbenchAccessControlDeriver::$basePluginId protected property The base plugin ID.
WorkbenchAccessControlDeriver::$entityFieldManager protected property Entity field manager.
WorkbenchAccessControlDeriver::$entityTypeManager protected property The entity type manager.
WorkbenchAccessControlDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
WorkbenchAccessControlDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
WorkbenchAccessControlDeriver::__construct public function Creates the DynamicLocalTasks object.