You are here

class EntityFieldConditionDeriver in Entity Field Condition 2.0.x

Define the entity field condition deriver.

Hierarchy

Expanded class hierarchy of EntityFieldConditionDeriver

File

src/Plugin/Deriver/EntityFieldConditionDeriver.php, line 19

Namespace

Drupal\entity_field_condition\Plugin\Deriver
View source
class EntityFieldConditionDeriver extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

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

  /**
   * The entity field condition deriver.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritDoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager'));
  }

  /**
   * {@inheritDoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) : array {
    if (empty($this->derivatives)) {
      foreach ($this->entityTypeManager
        ->getDefinitions() as $type => $definition) {
        if (!$definition instanceof ContentEntityTypeInterface || !$definition
          ->entityClassImplements(FieldableEntityInterface::class)) {
          continue;
        }
        $this->derivatives[$type] = $base_plugin_definition;
        $this->derivatives[$type]['label'] = $this
          ->t('@entity_type Field', [
          '@entity_type' => $definition
            ->getLabel(),
        ]);
        $this->derivatives[$type]['context_definitions'] = [
          'entity' => new EntityContextDefinition("entity:{$type}", $this
            ->t('@entity_type', [
            '@entity_type' => $definition
              ->getLabel(),
          ])),
        ];
      }
    }
    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
EntityFieldConditionDeriver::$entityTypeManager protected property Entity type manager service.
EntityFieldConditionDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EntityFieldConditionDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EntityFieldConditionDeriver::__construct public function The entity field condition deriver.
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.