public function AllowedHtmlManager::appliesTo in Markdown 8.2
Retrieves plugins that apply to a parser and active theme.
Note: this is primarily for use when actually parsing markdown.
Parameters
\Drupal\markdown\Plugin\Markdown\ParserInterface $parser: A markdown parser.
\Drupal\Core\Theme\ActiveTheme $activeTheme: Optional. The active them. This is used as an indicator when in "render mode".
array $definitions: Optional. Specific plugin definitions.
Return value
\Drupal\markdown\Plugin\Markdown\AllowedHtmlInterface[] Plugins that apply to the $parser.
File
- src/
PluginManager/ AllowedHtmlManager.php, line 150
Class
- AllowedHtmlManager
- Markdown Allowed HTML Plugin Manager.
Namespace
Drupal\markdown\PluginManagerCode
public function appliesTo(ParserInterface $parser, ActiveTheme $activeTheme = NULL, array $definitions = NULL) {
$instances = [];
foreach ($this
->getGroupedDefinitions($definitions) as $group => $groupDefinitions) {
// Filter group definitions based on enabled status of the parser when
// an active theme has been provided.
if ($activeTheme) {
$groupDefinitions = array_intersect_key($groupDefinitions, array_filter($parser
->getAllowedHtmlPlugins()));
}
switch ($group) {
case 'extension':
$groupDefinitions = $this
->getExtensionDefinitions($parser, $groupDefinitions, $activeTheme);
break;
case 'filter':
$filter = $parser instanceof FilterAwareInterface ? $parser
->getFilter() : NULL;
$filterFormat = $filter instanceof FilterFormatAwareInterface ? $filter
->getFilterFormat() : NULL;
$groupDefinitions = $this
->getFilterDefinitions($filterFormat, $groupDefinitions, $activeTheme);
break;
case 'parser':
$groupDefinitions = $this
->getParserDefinitions($parser, $groupDefinitions, $activeTheme);
break;
case 'theme':
// If an active theme was provided, then filter out the theme
// based plugins that are supported by the active theme.
if ($activeTheme) {
$groupDefinitions = $this
->getThemeDefinitions($groupDefinitions, $activeTheme);
}
break;
}
foreach (array_keys($groupDefinitions) as $plugin_id) {
try {
$instances[$plugin_id] = $this
->createInstance($plugin_id, [
'activeTheme' => $activeTheme,
'parser' => $parser,
]);
} catch (PluginException $e) {
// Intentionally do nothing.
}
}
}
return $instances;
}