diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e7ec8df..f398719 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2039,19 +2039,6 @@ function template_preprocess_field(&$variables, $hook) { // readers. $variables['label'] = String::checkPlain($element['#title']); - // We want other preprocess functions and the theme implementation to have - // fast access to the field item render arrays. The item render array keys - // (deltas) should always be numerically indexed starting from 0, and looping - // on those keys is faster than calling - // \Drupal\Core\Render\Element::children() or looping on all keys within - // $element, since that requires traversal of all element properties. - $variables['items'] = array(); - $delta = 0; - while (!empty($element[$delta])) { - $variables['items'][$delta] = $element[$delta]; - $delta++; - } - // Add default CSS classes. Since there can be many fields rendered on a page, // save some overhead by calling strtr() directly instead of // drupal_html_class(). @@ -2065,6 +2052,7 @@ function template_preprocess_field(&$variables, $hook) { 'field-type-' . $variables['field_type_css'], 'field-label-' . $element['#label_display'], ); + // Add a "clearfix" class to the wrapper since we float the label and the // field items in field.module.css if the label is inline. if ($element['#label_display'] == 'inline') { @@ -2081,15 +2069,26 @@ function template_preprocess_field(&$variables, $hook) { $default_attributes = new Attribute; } - // Modules (e.g., rdf.module) can add field item attributes (to - // $item->_attributes) within hook_entity_prepare_view(). Some field - // formatters move those attributes into some nested formatter-specific - // element in order have them rendered on the desired HTML element (e.g., on - // the element of a field item being rendered as a link). Other field - // formatters leave them within $element['#items'][$delta]['_attributes'] to - // be rendered on the item wrappers provided by field.html.twig. - foreach ($variables['items'] as $delta => $item) { - $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); + // We want other preprocess functions and the theme implementation to have + // fast access to the field item render arrays. The item render array keys + // (deltas) should always be numerically indexed starting from 0, and looping + // on those keys is faster than calling element_children() or looping on all + // keys within $element, since that requires traversal of all element + // properties. + $variables['items'] = array(); + $delta = 0; + while (!empty($element[$delta])) { + $variables['items'][$delta]['content'] = $element[$delta]; + + // Modules (e.g., rdf.module) can add field item attributes (to + // $item->_attributes) within hook_entity_prepare_view(). Some field + // formatters move those attributes into some nested formatter-specific + // element in order have them rendered on the desired HTML element (e.g., on + // the element of a field item being rendered as a link). Other field + // formatters leave them within $element['#items'][$delta]['_attributes'] to + // be rendered on the item wrappers provided by field.html.twig. + $variables['items'][$delta]['#attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); + $delta++; } } diff --git a/core/lib/Drupal/Core/Render/Element/MoreLink.php b/core/lib/Drupal/Core/Render/Element/MoreLink.php index 4f7e90c..6551abb 100644 --- a/core/lib/Drupal/Core/Render/Element/MoreLink.php +++ b/core/lib/Drupal/Core/Render/Element/MoreLink.php @@ -24,7 +24,7 @@ public function getInfo() { '#title' => $this->t('More'), '#theme_wrappers' => array( 'container' => array( - '#attributes' => array('class' => 'more-link'), + '#attributes' => array('class' => array('more-link')), ), ), ) + $info; diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 5b1ed9b..75572ad 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -841,7 +841,7 @@ function comment_preprocess_field(&$variables) { $variables['title_attributes']['class'][] = 'title'; // Append additional attributes (eg. RDFa) from the first field item. - $variables['attributes'] += $variables['item_attributes'][0]->storage(); + $variables['attributes'] += $variables['items'][0]['#attributes']->storage(); // Create separate variables for the comments and comment form. $variables['comments'] = $element[0]['comments']; diff --git a/core/modules/node/templates/field--node--title.html.twig b/core/modules/node/templates/field--node--title.html.twig index 25432c0..204e0b8 100644 --- a/core/modules/node/templates/field--node--title.html.twig +++ b/core/modules/node/templates/field--node--title.html.twig @@ -8,11 +8,17 @@ * * Available variables: * - attributes: HTML attributes for the containing span element. - * - items: List of all the field items. + * - items: List of all the field items. Each item contains: + * - #attributes: List of HTML attributes for each item. + * - content: The field item content. * * @see field.html.twig * * @ingroup themeable */ #} -{{ items }} + + {%- for item in items -%} + {{ item.content }} + {%- endfor -%} + diff --git a/core/modules/system/css/system.admin.css b/core/modules/system/css/system.admin.css index 853ded2..2c1269b 100644 --- a/core/modules/system/css/system.admin.css +++ b/core/modules/system/css/system.admin.css @@ -28,7 +28,7 @@ div.admin .expert-link { } /** - * Markup generated by theme_system_compact_link(). + * System compact link: to toggle the display of description text. */ .compact-link { margin: 0 0 0.5em 0; diff --git a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php index 6d83838..7a524ad 100644 --- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php +++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php @@ -184,4 +184,50 @@ function testMoreLink() { } } + /** + * Tests system #type 'system_compact_link'. + */ + function testSystemCompactLink() { + $elements = array( + array( + 'name' => "#type 'system_compact_link' when admin compact mode is off", + 'value' => array( + '#type' => 'system_compact_link', + ), + 'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact/on") and text()="Hide descriptions"]', + ), + array( + 'name' => "#type 'system_compact_link' when adding extra attributes", + 'value' => array( + '#type' => 'system_compact_link', + '#attributes' => array( + 'class' => array('kittens-rule'), + ), + ), + 'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact/on") and @class="kittens-rule" and text()="Hide descriptions"]', + ), + ); + + foreach($elements as $element) { + $xml = new \SimpleXMLElement(drupal_render($element['value'])); + $result = $xml->xpath($element['expected']); + $this->assertTrue($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().'); + } + + // Set admin compact mode on for additional tests. + \Drupal::request()->cookies->set('Drupal_visitor_admin_compact_mode', TRUE); + + $element = array( + 'name' => "#type 'system_compact_link' when admin compact mode is on", + 'value' => array( + '#type' => 'system_compact_link', + ), + 'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact/off") and text()="Show descriptions"]', + ); + + $xml = new \SimpleXMLElement(drupal_render($element['value'])); + $result = $xml->xpath($element['expected']); + $this->assertTrue($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().'); + } + } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 57edc26..0fc5922 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -84,7 +84,7 @@ function template_preprocess_admin_block_content(&$variables) { */ function template_preprocess_admin_page(&$variables) { $variables['system_compact_link'] = array( - '#theme' => 'system_compact_link', + '#type' => 'system_compact_link', ); $variables['containers'] = array(); $stripe = 0; @@ -113,7 +113,7 @@ function template_preprocess_admin_page(&$variables) { */ function template_preprocess_system_admin_index(&$variables) { $variables['system_compact_link'] = array( - '#theme' => 'system_compact_link', + '#type' => 'system_compact_link', ); $variables['containers'] = array(); $stripe = 0; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c863fdd..a5628bf 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -212,9 +212,6 @@ function system_theme() { 'file' => 'system.admin.inc', 'template' => 'system-admin-index', ), - 'system_compact_link' => array( - 'variables' => array(), - ), )); } @@ -1168,24 +1165,6 @@ function system_time_zones($blank = NULL) { } /** - * Returns HTML for a link to show or hide inline help descriptions. - * - * @ingroup themeable - */ -function theme_system_compact_link() { - $output = ''; - - return $output; -} - -/** * Attempts to get a file using Guzzle HTTP client and to store it locally. * * @param string $url diff --git a/core/modules/system/templates/field.html.twig b/core/modules/system/templates/field.html.twig index d38b028..80f4d93 100644 --- a/core/modules/system/templates/field.html.twig +++ b/core/modules/system/templates/field.html.twig @@ -21,8 +21,9 @@ * - title_attributes: HTML attributes for the title. * - label: The label for the field. * - content_attributes: HTML attributes for the content. - * - items: List of all the field items. - * - item_attributes: List of HTML attributes for each item. + * - items: List of all the field items. Each item contains: + * - #attributes: List of HTML attributes for each item. + * - content: The field item's content. * * @see template_preprocess_field() * @@ -31,11 +32,11 @@ #} {% if not label_hidden %} -
{{ label }}: 
+ {{ label }}:  {% endif %} -
- {% for delta, item in items %} -
{{ item }}
+ + {% for item in items %} + {{ item.content }}
{% endfor %} diff --git a/core/modules/user/src/Form/UserPermissionsForm.php b/core/modules/user/src/Form/UserPermissionsForm.php index 3f89bb6..1a6643a 100644 --- a/core/modules/user/src/Form/UserPermissionsForm.php +++ b/core/modules/user/src/Form/UserPermissionsForm.php @@ -97,7 +97,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $hide_descriptions = system_admin_compact_mode(); $form['system_compact_link'] = array( - '#theme' => 'system_compact_link', + '#type' => 'system_compact_link', ); $form['permissions'] = array( diff --git a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig index 4c579ee..c08299e 100644 --- a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig +++ b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig @@ -9,20 +9,21 @@ * - title_attributes: HTML attributes for the label. * - label: The label for the field. * - content_attributes: HTML attributes for the content. - * - items: List of all the field items. - * - item_attributes: List of HTML attributes for each item. + * - items: List of all the field items. Each item contains: + * - #attributes: List of HTML attributes for each item. + * - content: The field item's content. * * @see template_preprocess_field() * @see bartik_preprocess_field() */ #} -
+ {% if not label_hidden %} {{ label }}: {% endif %} -