You are here

abstract class EntityRoutingMapBase in Form mode manager 8.2

Same name and namespace in other branches
  1. 8 src/EntityRoutingMapBase.php \Drupal\form_mode_manager\EntityRoutingMapBase

Base class for form mode manager entity routing plugin.

This plugin are used to abstract the concepts implemented by EntityPlugin. In Entity API we have possibility to linked entity form 'handlers' to a, specific FormClass, but the operation name and routes linked with her are, very arbitrary and unpredictable specially in custom entities cases. In that plugin you have the possibility to map operation and, others useful information about entity to reduce complexity of, retrieving each possible cases.

Hierarchy

Expanded class hierarchy of EntityRoutingMapBase

5 files declare their use of EntityRoutingMapBase
BlockContent.php in src/Plugin/EntityRoutingMap/BlockContent.php
Generic.php in src/Plugin/EntityRoutingMap/Generic.php
Node.php in src/Plugin/EntityRoutingMap/Node.php
Term.php in src/Plugin/EntityRoutingMap/Term.php
User.php in src/Plugin/EntityRoutingMap/User.php

File

src/EntityRoutingMapBase.php, line 21

Namespace

Drupal\form_mode_manager
View source
abstract class EntityRoutingMapBase extends PluginBase implements EntityRoutingMapInterface, ContainerFactoryPluginInterface {
  use StringTranslationTrait;

  /**
   * Plugin label.
   *
   * @var string
   */
  protected $label;

  /**
   * Default form class Definition name.
   *
   * @var string
   */
  protected $defaultFormClass;

  /**
   * Default editing form class Definition name.
   *
   * @var string
   */
  protected $editFormClass;

  /**
   * Entity type id of entity.
   *
   * @var string
   */
  protected $targetEntityType;

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

  /**
   * Constructs display plugin.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this
      ->setTargetEntityType();
    $this
      ->setConfiguration($configuration);
    $this
      ->setDefaultFormClass();
    $this
      ->setEditFormClass();
    $this
      ->setContextualLinks();
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   *
   * @param string $operation_name
   *   The name of needed operation to retrieve.
   */
  public function getOperation($operation_name) {
    if (isset($this->pluginDefinition['operations'][$operation_name])) {
      return $this->pluginDefinition['operations'][$operation_name];
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getOperations() {
    return $this->pluginDefinition['operations'];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultFormClass() {
    return $this->defaultFormClass;
  }

  /**
   * {@inheritdoc}
   */
  public function getEditFormClass() {
    return $this->editFormClass;
  }

  /**
   * {@inheritdoc}
   */
  public function getContextualLinks() {
    return $this->pluginDefinition['contextualLinks'];
  }

  /**
   * {@inheritdoc}
   */
  public function getContextualLink($operation_name) {
    if (isset($this->pluginDefinition['contextualLinks'][$operation_name])) {
      return $this->pluginDefinition['contextualLinks'][$operation_name];
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $configuration += $this
      ->defaultConfiguration();
    if ($this
      ->getPluginId() === 'generic') {
      $this
        ->setTargetEntityType();
      $this
        ->setOperations();
    }
    $this->configuration = $configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setOperations() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function setDefaultFormClass() {
    $this->defaultFormClass = $this->pluginDefinition['defaultFormClass'];
  }

  /**
   * {@inheritdoc}
   */
  public function setEditFormClass() {
    $this->editFormClass = $this->pluginDefinition['editFormClass'];
  }

  /**
   * {@inheritdoc}
   */
  public function setContextualLinks() {
    if ($this
      ->doGenerateContextualLinks()) {
      $operations = [
        'edit' => "entity.{$this->targetEntityType}.edit_form",
      ];
      $this->pluginDefinition['contextualLinks'] += $operations;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getTargetEntityType() {
    return $this->targetEntityType;
  }

  /**
   * {@inheritdoc}
   */
  public function setTargetEntityType() {
    if (empty($this->pluginDefinition['targetEntityType']) && !empty($this->configuration['entityTypeId'])) {
      $this->pluginDefinition['targetEntityType'] = $this->configuration['entityTypeId'];
    }
    $this->targetEntityType = $this->pluginDefinition['targetEntityType'];
  }

  /**
   * {@inheritdoc}
   */
  public function label() {
    return $this->label;
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * Evaluate if current pluginDefinition contextualLink is applicable.
   *
   * @return bool
   *   True if we can generate the plugin definition or False if not.
   */
  private function doGenerateContextualLinks() {
    return is_array($this->pluginDefinition['contextualLinks']) && !isset($this->pluginDefinition['contextualLinks']['edit']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityRoutingMapBase::$defaultFormClass protected property Default form class Definition name.
EntityRoutingMapBase::$editFormClass protected property Default editing form class Definition name.
EntityRoutingMapBase::$entityTypeManager protected property The entity type manager service.
EntityRoutingMapBase::$label protected property Plugin label.
EntityRoutingMapBase::$targetEntityType protected property Entity type id of entity.
EntityRoutingMapBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
EntityRoutingMapBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
EntityRoutingMapBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 1
EntityRoutingMapBase::doGenerateContextualLinks private function Evaluate if current pluginDefinition contextualLink is applicable.
EntityRoutingMapBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
EntityRoutingMapBase::getContextualLink public function Return the contextual links mapping for given operation. Overrides EntityRoutingMapInterface::getContextualLink
EntityRoutingMapBase::getContextualLinks public function Return the contextual links mapping. Overrides EntityRoutingMapInterface::getContextualLinks
EntityRoutingMapBase::getDefaultFormClass public function Get the default form class Definition. Overrides EntityRoutingMapInterface::getDefaultFormClass
EntityRoutingMapBase::getEditFormClass public function Get the edit form class Definition. Overrides EntityRoutingMapInterface::getEditFormClass
EntityRoutingMapBase::getOperation public function Overrides EntityRoutingMapInterface::getOperation
EntityRoutingMapBase::getOperations public function Return the form operation route mapping. Overrides EntityRoutingMapInterface::getOperations
EntityRoutingMapBase::getTargetEntityType public function Gets the target entity type. Overrides EntityRoutingMapInterface::getTargetEntityType
EntityRoutingMapBase::label public function Returns the display label. Overrides EntityRoutingMapInterface::label
EntityRoutingMapBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
EntityRoutingMapBase::setContextualLinks public function Return contextual links route mapping. Overrides EntityRoutingMapInterface::setContextualLinks
EntityRoutingMapBase::setDefaultFormClass public function Set the default form class Definition. Overrides EntityRoutingMapInterface::setDefaultFormClass
EntityRoutingMapBase::setEditFormClass public function Set the edit form class Definition. Overrides EntityRoutingMapInterface::setEditFormClass
EntityRoutingMapBase::setOperations public function Set a mapping of operations for Generic plugin. Overrides EntityRoutingMapInterface::setOperations 1
EntityRoutingMapBase::setTargetEntityType public function Set the target entity type. Overrides EntityRoutingMapInterface::setTargetEntityType
EntityRoutingMapBase::__construct public function Constructs display plugin. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
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.