diff -u b/core/includes/theme.inc b/core/includes/theme.inc --- b/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -16,6 +16,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Config\Config; use Drupal\Core\Config\StorageException; +use Drupal\Core\Render\SafeString; use Drupal\Core\Template\Attribute; use Drupal\Core\Theme\ThemeSettings; use Drupal\Component\Utility\NestedArray; @@ -1066,6 +1067,73 @@ } /** + * Prepares variables for inline list templates. + * + * Default template: inline-list.html.twig. + * + * @param array $variables + * An associative array containing: + * - items: An array of items to be displayed in the list. Each item can be + * either a string or a render array. If #type, #theme, or #markup + * properties are not specified for child render arrays, they will be + * inherited from the parent list, allowing callers to specify larger + * nested lists without having to explicitly specify and repeat the + * render properties for all nested child lists. + * - separator: A string to separate list items. + * + * @see https://www.drupal.org/node/1842756 + */ +function template_preprocess_inline_list(&$variables) { + foreach ($variables['items'] as &$item) { + $attributes = array(); + // If the item value is an array, then it is a render array. + if (is_array($item)) { + // List items support attributes via the '#wrapper_attributes' property. + if (isset($item['#wrapper_attributes'])) { + $attributes = $item['#wrapper_attributes']; + } + // Determine whether there are any child elements in the item that are not + // fully-specified render arrays. If there are any, then the child + // elements present nested lists and we automatically inherit the render + // array properties of the current list to them. + foreach (Element::children($item) as $key) { + $child = &$item[$key]; + // If this child element does not specify how it can be rendered, then + // we need to inherit the render properties of the current list. + if (!isset($child['#type']) && !isset($child['#theme']) && !isset($child['#markup'])) { + // Since inline-list.html.twig supports both strings and render arrays + // as items, the items of the nested list may have been specified as + // the child elements of the nested list, instead of #items. For + // convenience, we automatically move them into #items. + if (!isset($child['#items'])) { + // This is the same condition as in + // \Drupal\Core\Render\Element::children(), which cannot be used + // here, since it triggers an error on string values. + foreach ($child as $child_key => $child_value) { + if ($child_key[0] !== '#') { + $child['#items'][$child_key] = $child_value; + unset($child[$child_key]); + } + } + } + // Lastly, inherit the original theme variables of the current list. + $child['#theme'] = $variables['theme_hook_original']; + } + } + } + + // Set the item's value and attributes for the template. + $item = array( + 'value' => $item, + 'attributes' => new Attribute($attributes), + ); + + // Since the separator may be user-specified, it must be sanitized. + $variables['separator'] = SafeString::create(Xss::filterAdmin($variables['separator'])); + } +} + +/** * Returns HTML for an indentation div; used for drag and drop tables. * * @param $variables @@ -1726,8 +1794,8 @@ 'item_list' => array( 'variables' => array('items' => array(), 'title' => '', 'list_type' => 'ul', 'attributes' => array(), 'empty' => NULL, 'context' => array()), ), - 'item_list__inline' => array( - 'variables' => array('items' => array(), 'title' => '', 'list_type' => 'inline', 'attributes' => array(), 'empty' => NULL, 'context' => array()), + 'inline_list' => array( + 'variables' => array('items' => array(), 'separator' => ', ', 'attributes' => array(), 'empty' => NULL, 'context' => array()), ), 'feed_icon' => array( 'variables' => array('url' => NULL, 'title' => NULL), reverted: --- b/core/modules/system/templates/item-list--inline.html.twig +++ /dev/null @@ -1,33 +0,0 @@ -{# -/** - * @file - * Default theme implementation for an item list for comma separated inline. - * - * Available variables: - * - items: A list of items. Each item contains: - * - attributes: HTML attributes to be applied to each list item. - * - value: The content of the list element. - * - title: The title of the list. - * - list_type: The tag for list element ("ul" or "ol"). - * - attributes: HTML attributes to be applied to the list. - * - empty: A message to display when there are no items. Allowed value is a - * string or render array. - * - * @see template_preprocess_item_list() - * - * @ingroup themeable - */ -#} -{% if items or empty -%} - {%- if title is not empty -%} -

{{ title }}

- {%- endif -%} - - {%- if items -%} - {%- for item in items -%} - {{ item }}{{ loop.last ? '' : ', ' }} - {%- endfor -%} - {%- else -%} - {{- empty -}} - {%- endif -%} -{%- endif %} diff -u b/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php --- b/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -109,7 +109,7 @@ 'tag' => $view->get('tag'), 'path' => array( 'data' => array( - '#theme' => 'item_list__inline', + '#theme' => 'inline_list', '#items' => $this->getDisplayPaths($view), ), ), only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/templates/inline-list.html.twig @@ -0,0 +1,29 @@ +{# +/** + * @file + * Default theme implementation for an inline list of items. + * + * Available variables: + * - items: A list of items. Each item contains: + * - attributes: HTML attributes to be applied to each list item. + * - value: The content of the list element. + * - separator: A string to separate list items. + * - list_type: The tag for list element ("ul" or "ol"). + * - attributes: HTML attributes to be applied to the list. + * - empty: A message to display when there are no items. Allowed value is a + * string or render array. + * + * @see template_preprocess_inline_list() + * + * @ingroup themeable + */ +#} +{% if items or empty -%} + {%- if items -%} + {%- for item in items -%} + {{ item.value }}{{ loop.last ? '' : separator }} + {%- endfor -%} + {%- else -%} + {{- empty -}} + {%- endif -%} +{%- endif %}