protected function ExtensionManager::alterDefinitions in Markdown 8.2
Invokes the hook to alter the definitions if the alter hook is set.
Parameters
$definitions: The discovered plugin definitions.
Overrides InstallablePluginManager::alterDefinitions
File
- src/
PluginManager/ ExtensionManager.php, line 61
Class
- ExtensionManager
- Markdown Extension Plugin Manager.
Namespace
Drupal\markdown\PluginManagerCode
protected function alterDefinitions(&$definitions, $runtime = FALSE) {
/** @var \Drupal\markdown\Annotation\MarkdownExtension[] $definitions */
// Create dependency relationships between extensions.
// Note: property is prefixed with an underscore to denote it as internal.
// @see \Drupal\markdown\PluginManager\ExtensionCollection::__construct
// @todo Figure out a better way to handle this.
foreach ($definitions as $definition) {
if (!isset($definition['_requiredBy'])) {
$definition['_requiredBy'] = [];
}
$extensionRequirements = $definition
->getRequirementsByType('extension');
foreach ($extensionRequirements as $requirement) {
$id = $requirement
->getTypeId();
// Check that the plugin exists.
if (!isset($definitions[$id])) {
throw new PluginNotFoundException($id);
}
// Extensions cannot require themselves.
if ($id === $definition->id) {
throw new InvalidPluginDefinitionException($definition->id, 'Extensions cannot require themselves.');
}
if (!isset($definitions[$id]['_requiredBy'])) {
$definitions[$id]['_requiredBy'] = [];
}
if (!in_array($definition->id, $definitions[$id]['_requiredBy'])) {
$definitions[$id]['_requiredBy'][] = $definition->id;
}
}
}
parent::alterDefinitions($definitions, $runtime);
}