Commit 497e76d5 authored by mstrelan's avatar mstrelan Committed by rikki_iki
Browse files

Issue #3215733 by mstrelan: Field label and empty div printed when list items are empty

parent 7801db6c
......@@ -64,6 +64,10 @@ trait ElementListClassTrait {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
if ($items->isEmpty()) {
return [];
}
$elements = parent::viewElements($items, $langcode);
$class = $this->getSetting('class');
......
......@@ -25,6 +25,10 @@ class ListStringListClassFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
if ($items->isEmpty()) {
return [];
}
$elements = [];
$attributes = new Attribute();
$class = $this->getSetting('class');
......
......@@ -26,6 +26,10 @@ class StringListClassFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
if ($items->isEmpty()) {
return [];
}
$elements = [];
$attributes = new Attribute();
$class = $this->getSetting('class');
......
......@@ -22,7 +22,7 @@ abstract class ElementClassFormatterTestBase extends BrowserTestBase {
use NodeCreationTrait;
use TestFileCreationTrait;
protected $defaultTheme = 'stark';
protected $defaultTheme = 'classy';
/**
* {@inheritdoc}
......
......@@ -36,6 +36,14 @@ class EntityReferenceListLabelClassFormatterTest extends ElementClassFormatterTe
$this->drupalGet($entity->toUrl());
$assert_session = $this->assertSession();
$assert_session->elementExists('css', 'ol.' . self::TEST_CLASS);
// Test no wrapper is printed when the field is empty.
$entity = EntityTest::create();
$entity->save();
$this->drupalGet($entity->toUrl());
$assert_session = $this->assertSession();
$assert_session->elementNotExists('css', '.field');
}
}
......@@ -34,6 +34,14 @@ class LinkListClassFormatterTest extends ElementClassFormatterTestBase {
$this->drupalGet($entity->toUrl());
$assert_session = $this->assertSession();
$assert_session->elementExists('css', 'ol.' . self::TEST_CLASS);
// Test no wrapper is printed when the field is empty.
$entity = EntityTest::create();
$entity->save();
$this->drupalGet($entity->toUrl());
$assert_session = $this->assertSession();
$assert_session->elementNotExists('css', '.field');
}
}
......@@ -34,6 +34,14 @@ class StringListClassFormatterTest extends ElementClassFormatterTestBase {
$this->drupalGet($entity->toUrl());
$assert_session = $this->assertSession();
$assert_session->elementExists('css', 'ol.' . self::TEST_CLASS);
// Test no wrapper is printed when the field is empty.
$entity = EntityTest::create();
$entity->save();
$this->drupalGet($entity->toUrl());
$assert_session = $this->assertSession();
$assert_session->elementNotExists('css', '.field');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment