SubstitutionManager.php in Linkit 8.5
File
src/SubstitutionManager.php
View source
<?php
namespace Drupal\linkit;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class SubstitutionManager extends DefaultPluginManager implements SubstitutionManagerInterface {
protected $entityTypeManager;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct('Plugin/Linkit/Substitution', $namespaces, $module_handler, 'Drupal\\linkit\\SubstitutionInterface', 'Drupal\\linkit\\Annotation\\Substitution');
$this
->alterInfo('linkit_substitution');
$this
->setCacheBackend($cache_backend, 'linkit_substitution');
$this->entityTypeManager = $entity_type_manager;
}
public function getApplicablePluginsOptionList($entity_type_id) {
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
$options = [];
foreach ($this
->filterPlugins($this
->getDefinitions(), $entity_type) as $id => $definition) {
$options[$id] = $definition['label'];
}
return $options;
}
protected function filterPlugins(array $definitions, EntityTypeInterface $entity_type) {
return array_filter($definitions, function ($definition) use ($entity_type) {
$class = $definition['class'];
return $class::isApplicable($entity_type);
});
}
}