EntityRoutingMapBase.php in Form mode manager 8
File
src/EntityRoutingMapBase.php
View source
<?php
namespace Drupal\form_mode_manager;
use Drupal\Component\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
abstract class EntityRoutingMapBase extends PluginBase implements EntityRoutingMapInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
protected $label;
protected $defaultFormClass;
protected $editFormClass;
protected $targetEntityType;
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
$this
->setDefaultFormClass();
$this
->setEditFormClass();
$this
->setTargetEntityType();
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
public function getOperation($operation_name) {
if (isset($this->pluginDefinition['operations'][$operation_name])) {
return $this->pluginDefinition['operations'][$operation_name];
}
return FALSE;
}
public function getOperations() {
return $this->pluginDefinition['operations'];
}
public function getConfiguration() {
return $this->configuration;
}
public function getDefaultFormClass() {
return $this->defaultFormClass;
}
public function getEditFormClass() {
return $this->editFormClass;
}
public function setConfiguration(array $configuration) {
$configuration += $this
->defaultConfiguration();
if ($this
->getPluginId() === 'generic') {
$this
->setTargetEntityType();
$this
->setOperations();
}
$this->configuration = $configuration;
}
public function setOperations() {
return FALSE;
}
public function setDefaultFormClass() {
$this->defaultFormClass = $this->pluginDefinition['defaultFormClass'];
}
public function setEditFormClass() {
$this->editFormClass = $this->pluginDefinition['editFormClass'];
}
public function getTargetEntityType() {
return $this->targetEntityType;
}
public function setTargetEntityType() {
if (empty($this->pluginDefinition['targetEntityType']) && !empty($this->configuration['entityTypeId'])) {
$this->pluginDefinition['targetEntityType'] = $this->configuration['entityTypeId'];
}
$this->targetEntityType = $this->pluginDefinition['targetEntityType'];
}
public function label() {
return $this->label;
}
public function calculateDependencies() {
return [];
}
public function defaultConfiguration() {
return [];
}
}