diff -u b/core/includes/theme.inc b/core/includes/theme.inc --- b/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1523,15 +1523,9 @@ // Creating variables for the template. $variables['entity_type'] = $element['#entity_type']; - $variables['field_name'] = strtr($element['#field_name'], '_', '-'); - $variables['field_type'] = strtr($element['#field_type'], '_', '-'); - $variables['field_label'] = strtr($element['#label_display'], '_', '-'); + $variables['field_name'] = $element['#field_name']; + $variables['field_type'] = $element['#field_type']; $variables['label_display'] = $element['#label_display']; - // Are there multiple field items. - $variables['multiple'] = FALSE; - if (isset($element['#items']) && is_callable($element['#items'], 'getFieldDefinition') && is_callable($element['#items']->getFieldDefinition(), 'isMultiple')) { - $variables['multiple'] = $element['#items']->getFieldDefinition()->isMultiple(); - } $variables['label_hidden'] = ($element['#label_display'] == 'hidden'); // Always set the field label - allow themes to decide whether to display it. @@ -1543,18 +1537,6 @@ if (!isset($default_attributes)) { $default_attributes = new Attribute; } - // Merge the attributes when its a multiple fields with hidden label - if ($element['#label_display'] == 'hidden' && $variables['multiple']) { - $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables['content_attributes']); - } - // Merge the attributes when its a single field with a label - if ($element['#label_display'] != 'hidden' && !$variables['multiple'] && is_object($element['#items'][0])) { - $variables['content_attributes'] = NestedArray::mergeDeep($variables['content_attributes'], (array) $element['#items'][0]->_attributes); - } - // Merge the attributes when its a single field with hidden label - if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && is_object($element['#items'][0])) { - $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables['content_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 @@ -1566,9 +1548,15 @@ // Creating variables for the template. $variables['entity_type'] = $element['#entity_type']; - $variables['field_name'] = $element['#field_name']; - $variables['field_type'] = $element['#field_type']; + $variables['field_name'] = strtr($element['#field_name'], '_', '-'); + $variables['field_type'] = strtr($element['#field_type'], '_', '-'); + $variables['field_label'] = strtr($element['#label_display'], '_', '-'); $variables['label_display'] = $element['#label_display']; + // Are there multiple field items. + $variables['multiple'] = FALSE; + if (isset($element['#items']) && is_callable($element['#items'], 'getFieldDefinition') && is_callable($element['#items']->getFieldDefinition(), 'isMultiple')) { + $variables['multiple'] = $element['#items']->getFieldDefinition()->isMultiple(); + } $variables['label_hidden'] = ($element['#label_display'] == 'hidden'); // Always set the field label - allow themes to decide whether to display it. @@ -1580,6 +1568,18 @@ if (!isset($default_attributes)) { $default_attributes = new Attribute; } + // Merge the attributes when its a multiple fields with hidden label + if ($element['#label_display'] == 'hidden' && $variables['multiple']) { + $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables['content_attributes']); + } + // Merge the attributes when its a single field with a label + if ($element['#label_display'] != 'hidden' && !$variables['multiple'] && is_object($element['#items'][0])) { + $variables['content_attributes'] = NestedArray::mergeDeep($variables['content_attributes'], (array) $element['#items'][0]->_attributes); + } + // Merge the attributes when its a single field with hidden label + if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && is_object($element['#items'][0])) { + $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables['content_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 reverted: --- b/core/themes/classy/templates/field/field.html.twig +++ a/core/themes/classy/templates/field/field.html.twig @@ -1,7 +1,7 @@ {# /** * @file + * Theme override for a field. - * Default theme implementation for a field. * * To override output, copy the "field.html.twig" from the templates directory * to your theme's directory and customize it, just like customizing other @@ -28,75 +28,38 @@ * - items: List of all the field items. Each item contains: * - attributes: List of HTML attributes for each item. * - content: The field item's content. - * - field_type: @todo: needs description - * - field_name: @todo: needs description - * - field_label: @todo: needs description * - entity_type: The entity type to which the field belongs. * - field_name: The name of the field. * - field_type: The type of the field. * - label_display: The display settings for the label. * * @see template_preprocess_field() - * - * @ingroup themeable */ #} +{% set field_name_class = field_name|clean_class %} - {% set classes = [ 'field', + 'field-' ~ entity_type|clean_class ~ '--' ~ field_name_class, + 'field-name-' ~ field_name_class, + 'field-type-' ~ field_type|clean_class, + 'field-label-' ~ label_display, + label_display == 'inline' ? 'clearfix', - 'field--type-' ~ field_type|clean_class, - 'field--name-' ~ field_name|clean_class, - 'field--label-' ~ label_display, ] %} +{% + set title_classes = [ + 'field-label', + label_display == 'visually_hidden' ? 'visually-hidden', + ] +%} +
Hello, world!
Hello, world!