diff --git a/core/includes/theme.inc b/core/includes/theme.inc index d45c2e5..8f22c22 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2315,9 +2315,11 @@ function template_preprocess_install_page(&$variables) { * - 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']); @@ -2336,6 +2338,30 @@ function template_preprocess_region(&$variables) { * - 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']; @@ -2358,24 +2384,15 @@ function template_preprocess_field(&$variables, $hook) { $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)) { @@ -2402,6 +2419,30 @@ function template_preprocess_field(&$variables, $hook) { foreach ($variables['items'] as $delta => $item) { $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); } + + //@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'; + + + // Merge the attributes when its a multiple fields with hidden label + if ($element['#label_display'] == 'hidden' && $variables['multiple']) { + $variables['attributes'] = mergeAttributes ($variables['attributes'], $variables['content_attributes']); + } + // 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']); + } + // 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']); + } + } /** diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index dd6d13e..0bd1721 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -340,7 +340,7 @@ function testNodeDisplay() { $output = '1'; } - $elements = $this->xpath('//div[text()="' . $output . '"]'); + $elements = $this->xpath('//div[text()=:output]', array(':output' => $output)); $this->assertEqual(count($elements), 1, 'Correct options found.'); } } diff --git a/core/modules/system/css/system.theme.css b/core/modules/system/css/system.theme.css index 3f31462..dfec576 100644 --- a/core/modules/system/css/system.theme.css +++ b/core/modules/system/css/system.theme.css @@ -612,19 +612,29 @@ table tr.error { .messages--error p.error { color: #a51b00; } +/* @todo: remove these test classes for attributes merging */ +div[role*="attributes-role"]{ background:gray;} +div[role*="title-attributes-role"]{font-style: italic; color:white;} +div[role*="content_attributes-role"]{ color:pink;} +div[role*="item-attributes-role"]{border:1px solid red;} +.test-attribute-merge-1{text-transform: uppercase;} +.test-attribute-merge-2{ font-size:30px;} +/* attribute merging test end */ +.field{ margin:10px 0;} /* Field display */ -.field .field-label { +.field__label { font-weight: bold; + vertical-align: top; } -.field-label-inline .field-label, -.field-label-inline .field-items { - float:left; /*LTR*/ +.field--label-inline .field__label, +.field--label-inline > .field__item, +.field--label-inline .field__items { + display: inline-block; padding-right: 0.5em; } -[dir="rtl"] .field-label-inline .field-label, -[dir="rtl"] .field-label-inline .field-items { - float: right; +[dir="rtl"] .field--label-inline .field__label, +[dir="rtl"] .field--label-inline .field__items { padding-left: 0.5em; } diff --git a/core/modules/system/templates/field.html.twig b/core/modules/system/templates/field.html.twig index a0d527a..1d7e219 100644 --- a/core/modules/system/templates/field.html.twig +++ b/core/modules/system/templates/field.html.twig @@ -17,25 +17,93 @@ * * Available variables: * - attributes: HTML attributes for the containing element. - * - label_hidden: Whether to show the field label or not. + * - label_visible: Whether to show the field label or not. * - 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. + * - field_type: @todo: needs description + * - field_name: @todo: needs description + * - field_label: @todo: needs description * * @see template_preprocess_field() * * @ingroup themeable */ #} -