Commit f258db4d authored by webchick's avatar webchick

Issue #2152203 by joelpittet, InternetDevels, rteijeiro, steveoliver,...

Issue #2152203 by joelpittet, InternetDevels, rteijeiro,  steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_container() to Twig.
parent 0990c7ee
......@@ -1824,20 +1824,16 @@ function theme_indentation($variables) {
}
/**
* Returns HTML to wrap child elements in a container.
* Prepares variables for container templates.
*
* Used for grouped form items. Can also be used as a #theme_wrapper for any
* renderable element, to surround it with a <div> and add attributes such as
* classes or an HTML id.
* Default template: container.html.twig.
*
* @param $variables
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #id, #attributes, #children.
*
* @ingroup themeable
*/
function theme_container($variables) {
function template_preprocess_container(&$variables) {
$element = $variables['element'];
// Ensure #attributes is set.
$element += array('#attributes' => array());
......@@ -1852,7 +1848,8 @@ function theme_container($variables) {
$element['#attributes']['class'][] = 'form-wrapper';
}
return '<div' . new Attribute($element['#attributes']) . '>' . $element['#children'] . '</div>';
$variables['children'] = $element['#children'];
$variables['attributes'] = $element['#attributes'];
}
/**
......@@ -2635,6 +2632,7 @@ function drupal_common_theme() {
),
'container' => array(
'render element' => 'element',
'template' => 'container',
),
);
}
......@@ -84,7 +84,7 @@ function testContainer() {
'#type' => 'container',
'#markup' => 'foo',
),
'expected' => '<div>foo</div>',
'expected' => '<div>foo</div>' . "\n",
),
// Container with a class.
array(
......@@ -96,7 +96,7 @@ function testContainer() {
'class' => 'bar',
),
),
'expected' => '<div class="bar">foo</div>',
'expected' => '<div class="bar">foo</div>' . "\n",
),
// Container with children.
array(
......@@ -107,7 +107,7 @@ function testContainer() {
'#markup' => 'foo',
),
),
'expected' => '<div>foo</div>',
'expected' => '<div>foo</div>' . "\n",
),
);
......
......@@ -91,7 +91,7 @@ function testDrupalRenderBasics() {
'#theme_wrappers' => array('container'),
'#attributes' => array('class' => 'baz'),
),
'expected' => '<div class="baz">foobar</div>',
'expected' => '<div class="baz">foobar</div>' . "\n",
),
// Test that #theme_wrappers can disambiguate element attributes shared
// with rendering methods that build #children by using the alternate
......@@ -109,7 +109,7 @@ function testDrupalRenderBasics() {
'#href' => 'http://drupal.org',
'#title' => 'bar',
),
'expected' => '<div class="baz"><a href="http://drupal.org" id="foo">bar</a></div>',
'expected' => '<div class="baz"><a href="http://drupal.org" id="foo">bar</a></div>' . "\n",
),
// Test that #theme_wrappers can disambiguate element attributes when the
// "base" attribute is not set for #theme.
......@@ -125,7 +125,7 @@ function testDrupalRenderBasics() {
),
),
),
'expected' => '<div class="baz"><a href="http://drupal.org">foo</a></div>',
'expected' => '<div class="baz"><a href="http://drupal.org">foo</a></div>' . "\n",
),
// Two 'container' #theme_wrappers, one using the "base" attributes and
// one using an override.
......@@ -140,7 +140,7 @@ function testDrupalRenderBasics() {
'container',
),
),
'expected' => '<div class="foo"><div class="bar"></div></div>',
'expected' => '<div class="foo"><div class="bar"></div>' . "\n" . '</div>' . "\n",
),
// Array syntax theme hook suggestion in #theme_wrappers.
array(
......@@ -149,7 +149,7 @@ function testDrupalRenderBasics() {
'#theme_wrappers' => array(array('container')),
'#attributes' => array('class' => 'foo'),
),
'expected' => '<div class="foo"></div>',
'expected' => '<div class="foo"></div>' . "\n",
),
// Test handling of #markup as a fallback for #theme hooks.
......@@ -865,7 +865,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() {
'#suffix' => '</foo>'
);
$container['test_element'] = $test_element;
$expected_output = '<div><foo><bar>' . $context['bar'] . '</bar></foo></div>';
$expected_output = '<div><foo><bar>' . $context['bar'] . '</bar></foo></div>' . "\n";
// #cache disabled.
drupal_static_reset('_drupal_add_js');
......@@ -938,7 +938,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() {
$this->assertIdentical($token, $expected_token, 'The tokens are identical for the parent element');
// Verify the token is in the cached element.
$expected_element = array(
'#markup' => '<div><foo><drupal:render-cache-placeholder callback="common_test_post_render_cache_placeholder" context="bar:' . $context['bar'] .';" token="'. $expected_token . '" /></foo></div>',
'#markup' => '<div><foo><drupal:render-cache-placeholder callback="common_test_post_render_cache_placeholder" context="bar:' . $context['bar'] .';" token="'. $expected_token . '" /></foo></div>' . "\n",
'#post_render_cache' => array(
'common_test_post_render_cache_placeholder' => array(
$expected_token => $context,
......
{#
/**
* @file
* Default theme implementation of a container used to wrap child elements.
*
* Used for grouped form items. Can also be used as a #theme_wrapper for any
* renderable element, to surround it with a <div> and HTML attributes.
*
* Available variables:
* - attributes: HTML attributes for the containing element.
* - children: The rendered child elements of the container.
*
* @see template_preprocess_container()
*
* @ingroup themeable
*/
#}
<div{{ attributes }}>{{ children }}</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment