You are here

class ViewsSynonymsEntityArgumentValidator in Synonyms 8

Same name and namespace in other branches
  1. 2.0.x modules/synonyms_views_argument_validator/src/Plugin/Derivative/ViewsSynonymsEntityArgumentValidator.php \Drupal\synonyms_views_argument_validator\Plugin\Derivative\ViewsSynonymsEntityArgumentValidator

Provides synonyms views argument validator for all entity types.

Hierarchy

Expanded class hierarchy of ViewsSynonymsEntityArgumentValidator

File

synonyms_views_argument_validator/src/Plugin/Derivative/ViewsSynonymsEntityArgumentValidator.php, line 16

Namespace

Drupal\synonyms_views_argument_validator\Plugin\Derivative
View source
class ViewsSynonymsEntityArgumentValidator extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The base plugin ID this derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

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

  /**
   * Constructs an ViewsSynonymsEntityArgumentValidator object.
   */
  public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
    $this->basePluginId = $base_plugin_id;
    $this->entityTypeManager = $entity_type_manager;
    $this->stringTranslation = $string_translation;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $entity_types = $this->entityTypeManager
      ->getDefinitions();
    $this->derivatives = [];
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if ($entity_type instanceof ContentEntityTypeInterface) {
        $this->derivatives[$entity_type_id] = [
          'id' => 'synonyms_entity:' . $entity_type_id,
          'provider' => 'synonyms',
          'title' => $this
            ->t('Synonyms of @entity_type', [
            '@entity_type' => $entity_type
              ->getSingularLabel(),
          ]),
          'help' => $this
            ->t('Validate @label', [
            '@label' => $entity_type
              ->getLabel(),
          ]),
          'entity_type' => $entity_type_id,
          'class' => $base_plugin_definition['class'],
        ];
      }
    }
    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. 1
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.
ViewsSynonymsEntityArgumentValidator::$basePluginId protected property The base plugin ID this derivative is for.
ViewsSynonymsEntityArgumentValidator::$entityTypeManager protected property The entity type manager.
ViewsSynonymsEntityArgumentValidator::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
ViewsSynonymsEntityArgumentValidator::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
ViewsSynonymsEntityArgumentValidator::__construct public function Constructs an ViewsSynonymsEntityArgumentValidator object.