EntityAliasTypeBase.php in View Mode Page 8.3
File
src/Plugin/view_mode_page/AliasType/EntityAliasTypeBase.php
View source
<?php
namespace Drupal\view_mode_page\Plugin\view_mode_page\AliasType;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginBase;
use Drupal\view_mode_page\AliasTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInterface, ContainerFactoryPluginInterface {
protected $moduleHandler;
protected $languageManager;
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
$this->languageManager = $language_manager;
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('module_handler'), $container
->get('language_manager'), $container
->get('entity_type.manager'));
}
public function getLabel() {
$definition = $this
->getPluginDefinition();
return (string) $definition['label'];
}
public function getTokenTypes() {
$definition = $this
->getPluginDefinition();
return $definition['types'];
}
protected function getEntityTypeId() {
return $this
->getDerivativeId();
}
public function calculateDependencies() {
$dependencies = [];
$dependencies['module'][] = $this->entityTypeManager
->getDefinition($this
->getEntityTypeId())
->getProvider();
return $dependencies;
}
public function applies($object) {
return $object instanceof FieldableEntityInterface && $object
->getEntityTypeId() == $this
->getEntityTypeId();
}
}