diff --git a/core/modules/user/src/Tests/Views/UserChangedTest.php b/core/modules/user/src/Tests/Views/UserChangedTest.php index 290dabf..7ee4a2c 100644 --- a/core/modules/user/src/Tests/Views/UserChangedTest.php +++ b/core/modules/user/src/Tests/Views/UserChangedTest.php @@ -49,7 +49,9 @@ public function testChangedField() { $this->drupalGet($path, $options); - $this->assertText(t('Updated date') . ': ' . date('Y-m-d', REQUEST_TIME)); + $this->assertTextPattern('/' . preg_quote(t('Updated date'), '/') . '\:\s+' + . preg_quote(date('Y-m-d', REQUEST_TIME), '/') + . '/'); } } diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index f13b8db..9eb3f3d 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -232,7 +232,7 @@ public function elementType($none_supported = FALSE, $default_empty = FALSE, $in } } if ($this->options['element_type']) { - return String::checkPlain($this->options['element_type']); + return $this->options['element_type']; } if ($default_empty) { @@ -260,7 +260,7 @@ public function elementLabelType($none_supported = FALSE, $default_empty = FALSE } } if ($this->options['element_label_type']) { - return String::checkPlain($this->options['element_label_type']); + return $this->options['element_label_type']; } if ($default_empty) { @@ -280,7 +280,7 @@ public function elementWrapperType($none_supported = FALSE, $default_empty = FAL } } if ($this->options['element_wrapper_type']) { - return String::checkPlain($this->options['element_wrapper_type']); + return $this->options['element_wrapper_type']; } if ($default_empty) { diff --git a/core/modules/views/templates/views-view-fields.html.twig b/core/modules/views/templates/views-view-fields.html.twig index a8aa00b..392f76e 100644 --- a/core/modules/views/templates/views-view-fields.html.twig +++ b/core/modules/views/templates/views-view-fields.html.twig @@ -11,13 +11,15 @@ * - class: The safe class ID to use. * - handler: The Views field handler controlling this field. * - inline: Whether or not the field should be inline. - * - inline_html: Either div or span based on the 'inline' flag. - * - wrapper_prefix: A complete wrapper containing the inline_html to use. - * - wrapper_suffix: The closing tag for the wrapper. + * - wrapper_element: An HTML element for a wrapper. + * - wrapper_attributes: List of attributes for wrapper element. * - separator: An optional separator that may appear before a field. * - label: The field's label text. - * - label_html: The full HTML of the label to use including configured - * element type. + * - label_element: An HTML element for a label wrapper. + * - label_attributes: List of attributes for label wrapper. + * - label_suffix: Colon after the label. + * - element_type: An HTML element for the field content. + * - element_attributes: List of attributes for HTML element for field content. * - row: The raw result from the query, with all data it fetched. * * @see template_preprocess_views_view_fields() @@ -25,17 +27,24 @@ * @ingroup themeable */ #} - {% for field in fields %} {{ field.separator }} - - {{ field.wrapper_prefix }} - {{ field.label_html }} - {{ field.content }} - {{ field.wrapper_suffix }} + {% if field.wrapper_element %} + <{{ field.wrapper_element }} {{ field.wrapper_attributes }}> + {% endif %} + {% if field.label %} + {% if field.label_element %} + <{{ field.label_element }} {{ field.label_attributes }}>{{ field.label }}{{ field.label_suffix }} + {% else %} + {{ field.label }}{{ field.label_suffix }} + {% endif %} + {% endif %} + {% if field.element_type %} + <{{ field.element_type }} {{ field.element_attributes }}>{{ field.content }} + {% else %} + {{ field.content }} + {% endif %} + {% if field.wrapper_element %} + + {% endif %} {% endfor %} diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index d4fb797..20032e8 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -106,16 +106,7 @@ function template_preprocess_views_view_fields(&$variables) { $attributes['class'][] = $classes; } $attributes = new Attribute($attributes); - - $pre = '<' . $object->element_type; - $pre .= $attributes; - $field_output = $pre . '>' . $field_output . 'element_type . '>'; - } - - // Protect ourself somewhat for backward compatibility. This will prevent - // old templates from producing invalid HTML when no element type is selected. - if (empty($object->element_type)) { - $object->element_type = 'span'; + $object->element_attributes = $attributes; } $object->content = $field_output; @@ -130,19 +121,18 @@ function template_preprocess_views_view_fields(&$variables) { $object->separator = Xss::filterAdmin($variables['options']['separator']); } - $object->class = drupal_clean_css_identifier($id); + $object->class = Html::cleanCssIdentifier($id); $previous_inline = $object->inline; - $object->inline_html = $object->handler->elementWrapperType(TRUE, TRUE); - if ($object->inline_html === '' && $variables['options']['default_field_elements']) { - $object->inline_html = $object->inline ? 'span' : 'div'; - } - // Set up the wrapper HTML. - $object->wrapper_prefix = ''; - $object->wrapper_suffix = ''; + // Set up field wrapper element. + $object->wrapper_element = $object->handler->elementWrapperType(TRUE, TRUE); + if ($object->wrapper_element === '' && $variables['options']['default_field_elements']) { + $object->wrapper_element = $object->inline ? 'span' : 'div'; + } - if ($object->inline_html) { + // Set up field wrapper attributes if field wrapper was set. + if ($object->wrapper_element) { $attributes = array(); if ($object->handler->options['element_default_classes']) { $attributes['class'][] = 'views-field'; @@ -152,44 +142,41 @@ function template_preprocess_views_view_fields(&$variables) { if ($classes = $object->handler->elementWrapperClasses($row->index)) { $attributes['class'][] = $classes; } + $attributes = new Attribute($attributes); + $object->wrapper_attributes = $attributes; - $object->wrapper_prefix = '<' . $object->inline_html; - $object->wrapper_prefix .= $attributes; - $object->wrapper_prefix .= '>'; - $object->wrapper_suffix = 'inline_html . '>'; } - // Set up the label for the value and the HTML to make it easier - // on the template. - $object->label = String::checkPlain($view->field[$id]->label()); - $object->label_html = ''; + // Set up field label. + $object->label = $view->field[$id]->label(); + + // Set up field label wrapper and its attributes. if ($object->label) { - $object->label_html .= $object->label; + + // Add a colon in a label suffix. if ($object->handler->options['element_label_colon']) { - $object->label_html .= ': '; + $object->label_suffix = ': '; } - $object->elementLabelType = $object->handler->elementLabelType(TRUE, !$variables['options']['default_field_elements']); - if ($object->elementLabelType) { + // Set up label HTML element + $object->label_element = $object->handler->elementLabelType(TRUE, !$variables['options']['default_field_elements']); + + // Set up label attributes + if ($object->label_element) { $attributes = array(); if ($object->handler->options['element_default_classes']) { $attributes['class'][] = 'views-label'; $attributes['class'][] = 'views-label-' . $object->class; } - $element_label_class = $object->handler->elementLabelClasses($row->index); if ($element_label_class) { $attributes['class'][] = $element_label_class; } $attributes = new Attribute($attributes); - - $pre = '<' . $object->elementLabelType; - $pre .= $attributes; - $pre .= '>'; - - $object->label_html = $pre . $object->label_html . 'elementLabelType . '>'; + $object->label_attributes = $attributes; } + } $variables['fields'][$id] = $object; @@ -199,39 +186,6 @@ function template_preprocess_views_view_fields(&$variables) { } /** - * Returns HTML for multiple views fields. - * - * @param $variables - * An associative array containing: - * - fields: An array of field objects. Each field object contains: - * - separator: A string that separates the fields. - * - wrapper_suffix: A string added to the beginning of the fields. - * - label_html: An HTML string that labels the fields. - * - content: The fields. - * - wrapper_suffix: A string added to the end of the fields. - * - * @see template_preprocess_views_view_fields() - */ -function theme_views_view_fields($variables) { - $fields = $variables['fields']; - $output = ''; - - foreach ($fields as $field) { - if (!empty($field->separator)) { - $output .= $field->separator; - } - - $output .= $field->wrapper_prefix; - $output .= $field->label_html; - $output .= $field->content; - - $output .= $field->wrapper_suffix; - } - - return $output; -} - -/** * Prepares variables for views single grouping templates. * * Default template: views-view-grouping.html.twig.