$elements_string =
preg_replace_callback('/<(\$[a-z][0-9a-z\-]*|\*)/',
function D
$matches) use (&
$replaced_wildcard_tags) { $wildcard_tag_name =
$matches[1
];
$replacement =
$wildcard_tag_name === '*'
? 'preprocessed-global-attribute__'
:
sprintf("preprocessed-wildcard-%s__",
substr($wildcard_tag_name, 1
));
$replaced_wildcard_tags[$replacement] =
$wildcard_tag_name;
return "<
$replacement";
},
$elements_string);
// Reuse the parsing logic from FilterHtml::getHTMLRestrictions().
$configuration =
['settings' =>
['allowed_html' =>
$elements_string]];
$filter =
new FilterHtml($configuration, 'filter_html',
['provider' => 'filter'
]);
$allowed_elements =
$filter->
getHTMLRestrictions()['allowed'
];
// Omit the broad wildcard addition that FilterHtml::getHTMLRestrictions()
// always sets; it is specific to how FilterHTML works and irrelevant here.
unset($allowed_elements['*'
]);
// @see \Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions()
// @todo remove this in https://www.drupal.org/project/drupal/issues/3226368
// cSpell:disable-next-line
unset($allowed_elements['__zqh6vxfbk3cg__'
]);
// Postprocess tag wildcards: convert
// `<preprocessed-wildcard-text-container__>` to `<$text-container>`.