Problem/Motivation
I am worried about RDF module adding markup into variables in preprocess.
- We'll want to turn on auto-escape eventually in Twig, and that means we need to keep data separate from markup so twig can escape things properly.
- By collapsing both the RDF span element and the current variable into a single variable here, modules that come later and themes won't be able to change anything in this variable without running a regex on the string.
- and, for a module or theme to reuse these RDF attributes on another element in the node template, all the code from the RDF preprocessor would need to be run again since they'd be impossible to get out of the current variable without a regex
Proposed resolution
I think the solution would be for RDF module to provide it's own twig template that would wrap a variable in a span tag, and add the appropriate attributes. Something like this:
<?php
function template_preprocess_rdf_wrapper($variables) {
$element = $variables['element'];
$variables['attributes'] = new Attribute($element['#attributes']);
$variables['children'] = $element['#children'];
}
?>
and the template:
{#
/**
* @file
* Default theme implementation of an RDF wrapper used to wrap child elements.
*
* Available variables:
* - attributes: Remaining html attributes for the containing element.
* - children: The rendered child elements of the container.
*
* @see template_preprocess_rdf_wrapper()
*
* @ingroup themeable
*/
#}
<span{{ attributes }}>{{ children }}</span>
Remaining tasks
Create a new rdf_wrapper preprocess function
Create a RDF wrapper template
Replace all concatenation of HTML + variable srtings with render arrays
User interface changes
none
API changes
new theme function, theme_rdf_wrapper
Related Issues
#1706612: remove 'submitted' variable in templates for ease of theme development
#1941286: Remove the process layer (rdf module)
#1778122: Provide a way for modules like RDF to inject attributes in field formatters