diff -u b/core/includes/theme.inc b/core/includes/theme.inc --- b/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -21,6 +21,7 @@ use Drupal\Core\Theme\ThemeSettings; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Render\Element; +use Zend\Stdlib\ArrayUtils; /** * @defgroup content_flags Content markers @@ -2315,11 +2316,9 @@ * - elements: An associative array containing properties of the region. */ function template_preprocess_region(&$variables) { - $elements = $variables['elements']; - // Create the $content variable that templates expect. - $variables['content'] = $elements['#children']; - $variables['region'] = $elements['#region']; + $variables['content'] = $variables['elements']['#children']; + $variables['region'] = $variables['elements']['#region']; $variables['attributes']['class'][] = 'region'; $variables['attributes']['class'][] = drupal_html_class('region-' . $variables['region']); @@ -2338,30 +2337,6 @@ * - content_attributes: A string containing the attributes for the content's * div. */ - -/** - * @todo this should probably be in another place - * but gets the job done & merge the arrays for field attributes - */ -function mergeAttributes($array) { - $mergedAttributes = array(); - foreach(func_get_args() as $argument) { - foreach($argument as $key => $value) { - if (!isset($mergedAttributes[$key]) ) { - $mergedAttributes[$key] = array(); - } - if (is_array($value)) { - foreach($value as $innerValue) { - $mergedAttributes[$key][] = $innerValue; - } - } else { - $mergedAttributes[$key][] = $value; - } - } - } - return $mergedAttributes; -} - function template_preprocess_field(&$variables, $hook) { $element = $variables['element']; @@ -2384,15 +2359,24 @@ $delta++; } - // Are there multiple field items. - if ( isset($element['#items']) && is_object($element['#items']) ){ - $variables['multiple'] = $element['#items']->getFieldDefinition()->isMultiple(); + // 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(). + $variables['entity_type_css'] = strtr($element['#entity_type'], '_', '-'); + $variables['field_name_css'] = strtr($element['#field_name'], '_', '-'); + $variables['field_type_css'] = strtr($element['#field_type'], '_', '-'); + $variables['attributes']['class'] = array( + 'field', + 'field-' . $variables['entity_type_css'] . '--' . $variables['field_name_css'], + 'field-name-' . $variables['field_name_css'], + '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') { + $variables['attributes']['class'][] = 'clearfix'; } - // Add default CSS class names. Since there can be many fields rendered on a - // page, save some overhead by calling strtr() - $variables['field_name'] = strtr($element['#field_name'], '_', '-'); - $variables['field_type'] = strtr($element['#field_type'], '_', '-'); - $variables['field_label'] = strtr($element['#label_display'], '_', '-'); static $default_attributes; if (!isset($default_attributes)) { @@ -2413,9 +2397,11 @@ * - elements: An associative array containing properties of the region. */ function template_preprocess_region(&$variables) { + $elements = $variables['elements']; + // Create the $content variable that templates expect. - $variables['content'] = $variables['elements']['#children']; - $variables['region'] = $variables['elements']['#region']; + $variables['content'] = $elements['#children']; + $variables['region'] = $elements['#region']; $variables['attributes']['class'][] = 'region'; $variables['attributes']['class'][] = drupal_html_class('region-' . $variables['region']); @@ -2456,24 +2442,15 @@ $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(). - $variables['entity_type_css'] = strtr($element['#entity_type'], '_', '-'); - $variables['field_name_css'] = strtr($element['#field_name'], '_', '-'); - $variables['field_type_css'] = strtr($element['#field_type'], '_', '-'); - $variables['attributes']['class'] = array( - 'field', - 'field-' . $variables['entity_type_css'] . '--' . $variables['field_name_css'], - 'field-name-' . $variables['field_name_css'], - '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') { - $variables['attributes']['class'][] = 'clearfix'; + // Are there multiple field items. + if ( isset($element['#items']) && is_object($element['#items']) ){ + $variables['multiple'] = $element['#items']->getFieldDefinition()->isMultiple(); } + // Add default CSS class names. Since there can be many fields rendered on a + // page, save some overhead by calling strtr() + $variables['field_name'] = strtr($element['#field_name'], '_', '-'); + $variables['field_type'] = strtr($element['#field_type'], '_', '-'); + $variables['field_label'] = strtr($element['#label_display'], '_', '-'); static $default_attributes; if (!isset($default_attributes)) { @@ -2502,26 +2479,25 @@ } //@todo this is dummy data for testing merging of the attributes remove when merge works. - // $variables['attributes']['class'] = 'test-attribute-merge-1'; - // $variables['content_attributes']['class'] ='test-attribute-merge-2'; - - // $variables['content_attributes']['role'] = 'content_attributes-role'; - // $variables['attributes']['role'] = 'attributes-role'; - // $variables['title_attributes']['role'] = 'title-attributes-role'; - // $variables['item_attributes']['0']['role'] = 'item-attributes-role'; - + $variables['attributes']['class'] = 'test-attribute-merge-1'; + $variables['content_attributes']['class'] ='test-attribute-merge-1'; + $variables['content_attributes']['role'] = 'content_attributes-role'; + $variables['attributes']['role'] = 'attributes-role'; + $variables['title_attributes']['role'] = 'title-attributes-role'; + $variables['item_attributes']['0']['role'] = 'item-attributes-role'; - // Merge the attributes when its a multiple fields with hidden label + //@todo: merge attributes for fields if ($element['#label_display'] == 'hidden' && $variables['multiple']) { - $variables['attributes'] = mergeAttributes ($variables['attributes'], $variables['content_attributes']); + //@todo: merge $variables['attributes'] and $variables['content_attributes'] + // $variables['attributes'] = NestedArray::mergeDeep($variables['attributes']->storage(), $variables['content_attributes']->storage()); } - // Merge the attributes when its a single field with a label if ($element['#label_display'] != 'hidden' && !$variables['multiple']) { - $variables['content_attributes'] = mergeAttributes ($variables['content_attributes'], $variables['item_attributes']['0']); + //@todo: merge $variables['item_attributes'][0] and $variables['content_attributes'] + //$variables['content_attributes'] = NestedArray::mergeDeep($variables['content_attributes']->storage(), $variables['item_attributes']['0']->storage()); } - // Merge the attributes when its a single field with hidden label if ($element['#label_display'] == 'hidden' && !$variables['multiple']) { - $variables['attributes'] = mergeAttributes ($variables['attributes'], $variables['content_attributes'], $variables['item_attributes']['0']); + //@todo: merge $variables['attributes'], $variables['item_attributes'][0] & $variables['content_attributes'] + // $variables['attributes'] = NestedArray::mergeDeep($variables['attributes']->storage(), $variables['content_attributes']->storage(), $variables['item_attributes']['0']->storage()); } } diff -u b/core/modules/system/templates/field.html.twig b/core/modules/system/templates/field.html.twig --- b/core/modules/system/templates/field.html.twig +++ b/core/modules/system/templates/field.html.twig @@ -54,10 +54,10 @@ #}
-
{{ label }}:
-
+
{{ label }}:
+
{% for delta, item in items %} -
{{ item }}
+
{{ item }}
{% endfor %}
@@ -72,9 +72,9 @@
attributes are merged with content_attributes #} -
+
{% for delta, item in items %} -
{{ item }}
+
{{ item }}
{% endfor %}
@@ -88,9 +88,9 @@ content_attributes are merged with item_attributes #}
-
{{ label }}:
+
{{ label }}:
{% for delta, item in items %} -
{{ item }}
+
{{ item }}
{% endfor %}