diff --git a/core/includes/theme.inc b/core/includes/theme.inc index cfdfa89..e3022e2 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1490,8 +1490,6 @@ function template_preprocess_region(&$variables) { * - element: A render element representing the field. * - attributes: A string containing the attributes for the wrapping div. * - title_attributes: A string containing the attributes for the title. - * - content_attributes: A string containing the attributes for the content's - * div. */ function template_preprocess_field(&$variables, $hook) { $element = $variables['element']; @@ -1501,6 +1499,11 @@ function template_preprocess_field(&$variables, $hook) { $variables['field_name'] = $element['#field_name']; $variables['field_type'] = $element['#field_type']; $variables['label_display'] = $element['#label_display']; + if (method_exists($element['#items'], 'getFieldDefinition')) { + $fieldStorageDefinition = $element['#items']->getFieldDefinition() + ->getFieldStorageDefinition(); + $variables['cardinality'] = $fieldStorageDefinition->getCardinality(); + } $variables['label_hidden'] = ($element['#label_display'] == 'hidden'); // Always set the field label - allow themes to decide whether to display it. diff --git a/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php b/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php index 362f269..b708f32 100644 --- a/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php +++ b/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php @@ -47,15 +47,17 @@ protected function setUp() { function testEntityViewController() { $get_label_markup = function($label) { return '

-
-
' . $label . '
-
-
+
+
' . $label . '
+
+

'; }; foreach ($this->entities as $entity) { $this->drupalGet('entity_test/' . $entity->id()); + file_put_contents('output_actual.html', $this->getRawContent()); + file_put_contents('output_expected.html', $get_label_markup($entity->label())); $this->assertRaw($entity->label()); $this->assertRaw($get_label_markup($entity->label())); $this->assertRaw('full'); diff --git a/core/themes/classy/templates/field/field.html.twig b/core/themes/classy/templates/field/field.html.twig index 5ab1e92..2dea023 100644 --- a/core/themes/classy/templates/field/field.html.twig +++ b/core/themes/classy/templates/field/field.html.twig @@ -24,7 +24,6 @@ * - label_hidden: 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. Each item contains: * - attributes: List of HTML attributes for each item. * - content: The field item's content. @@ -32,6 +31,7 @@ * - field_name: The name of the field. * - field_type: The type of the field. * - label_display: The display settings for the label. + * - cardinality: The maximum possible number of items as set in the field configuration. * * @see template_preprocess_field() */ @@ -57,9 +57,13 @@ {% if not label_hidden %} {{ label }} {% endif %} - - {% for item in items %} - {{ item.content }} - {% endfor %} - + {% if cardinality != 1 %} +
+ {% endif %} + {% for item in items %} + {{ item.content }}
+ {% endfor %} + {% if cardinality != 1 %} + + {% endif %}