alterInfo('linkit_substitution'); $this->setCacheBackend($cache_backend, 'linkit_substitution'); $this->entityTypeManager = $entity_type_manager; } /** * {@inheritdoc} */ 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; } /** * Filter the list of plugins by their applicability. * * @param array $definitions * An array of plugin definitions. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type to get applicable plugins for. * * @return array * The definitions appropriate for the given entity type. * * @see SubstitutionInterface::isApplicable() */ protected function filterPlugins(array $definitions, EntityTypeInterface $entity_type) { return array_filter($definitions, function ($definition) use ($entity_type) { /** @var \Drupal\linkit\SubstitutionInterface $class */ $class = $definition['class']; return $class::isApplicable($entity_type); }); } }