diff --git a/src/Plugin/DsField/BlockBase.php b/src/Plugin/DsField/BlockBase.php
index 3f64632..9ea4a5a 100644
--- a/src/Plugin/DsField/BlockBase.php
+++ b/src/Plugin/DsField/BlockBase.php
@@ -35,7 +35,12 @@ abstract class BlockBase extends DsFieldBase {
// Get render array.
$block_elements = $block->build();
- return $block_elements;
+ // Return an empty array if there is nothing to render.
+ if (\Drupal\Core\Render\Element::isEmpty($block_elements)){
+ return [];
+ } else {
+ return $block_elements;
+ }
}
/**
diff --git a/src/Tests/LayoutFluidTest.php b/src/Tests/LayoutFluidTest.php
new file mode 100644
index 0000000..67d2be3
--- /dev/null
+++ b/src/Tests/LayoutFluidTest.php
@@ -0,0 +1,88 @@
+drupalGet('admin/structure/types/manage/article/display');
+ $this->assertRaw('Test Fluid two column', 'Test Fluid two column layout found');
+
+ $layout = array(
+ 'layout' => 'dstest_2col_fluid',
+ );
+
+ $assert = array(
+ 'regions' => array(
+ 'left' => '
' . t('Left') . ' | ',
+ 'right' => '' . t('Right') . ' | ',
+ ),
+ );
+
+ $fields = array(
+ 'fields[node_author][region]' => 'left',
+ 'fields[node_links][region]' => 'left',
+ 'fields[body][region]' => 'left',
+ );
+
+ $this->dsSelectLayout($layout, $assert);
+ $this->dsConfigureUI($fields);
+
+ // Create a node.
+ $settings = array('type' => 'article');
+ $node = $this->drupalCreateNode($settings);
+
+ $this->drupalGet('node/' . $node->id());
+ $this->assertRaw('group-left', 'Template found (region left)');
+ $this->assertNoRaw('group-right', 'Empty region right hidden');
+ $this->assertRaw('group-one-column', 'Group one column class set');
+ $this->assertRaw('dstest-2col-fluid.css', 'Css file included');
+
+ // Add fields to the right column
+ $fields = array(
+ 'fields[node_author][region]' => 'left',
+ 'fields[node_links][region]' => 'left',
+ 'fields[body][region]' => 'right',
+ );
+
+ $this->dsSelectLayout($layout, $assert);
+ $this->dsConfigureUI($fields);
+
+ $this->drupalGet('node/' . $node->id());
+ $this->assertRaw('group-left', 'Template found (region left)');
+ $this->assertRaw('group-right', 'Template found (region right)');
+ $this->assertNoRaw('group-one-column', 'Group one column class not set');
+
+ // Move all fields to the right column
+ $fields = array(
+ 'fields[node_author][region]' => 'right',
+ 'fields[node_links][region]' => 'right',
+ 'fields[heavy_field][region]' => 'right',
+ 'fields[body][region]' => 'right',
+ );
+
+ $this->dsSelectLayout($layout, $assert);
+ $this->dsConfigureUI($fields);
+
+ $this->drupalGet('node/' . $node->id());
+ $this->assertNoRaw('group-left', 'Empty region left hidden');
+ $this->assertRaw('group-right', 'Template found (region right)');
+ $this->assertRaw('group-one-column', 'Group one column class set');
+
+ }
+
+}
diff --git a/templates/ds-2col-fluid.html.twig b/templates/ds-2col-fluid.html.twig
index d85ee16..4b64910 100644
--- a/templates/ds-2col-fluid.html.twig
+++ b/templates/ds-2col-fluid.html.twig
@@ -15,6 +15,9 @@
*/
#}
+{% set left = left|render %}
+{% set right = right|render %}
+
{% if (left and not right) or (right and not left) %}
{% set layout_class = 'group-one-column' %}
{% endif %}
diff --git a/templates/ds-2col-stacked-fluid.html.twig b/templates/ds-2col-stacked-fluid.html.twig
index 00ac43e..07c0194 100644
--- a/templates/ds-2col-stacked-fluid.html.twig
+++ b/templates/ds-2col-stacked-fluid.html.twig
@@ -21,6 +21,9 @@
*/
#}
+{% set left = left|render %}
+{% set right = right|render %}
+
{% if (left and not right) or (right and not left) %}
{% set layout_class = 'group-one-column' %}
{% endif %}
diff --git a/templates/ds-3col-stacked-fluid.html.twig b/templates/ds-3col-stacked-fluid.html.twig
index 57c730d..2baa5e7 100644
--- a/templates/ds-3col-stacked-fluid.html.twig
+++ b/templates/ds-3col-stacked-fluid.html.twig
@@ -24,6 +24,10 @@
*/
#}
+{% set left = left|render %}
+{% set middle = middle|render %}
+{% set right = right|render %}
+
{% if (left and not right) or (right and not left) %}
{% set layout_class = 'group-one-sidebar' %}
{% elseif (left and right) %}
diff --git a/tests/modules/ds_test/css/dstest-2col-fluid.css b/tests/modules/ds_test/css/dstest-2col-fluid.css
new file mode 100644
index 0000000..d9ba3be
--- /dev/null
+++ b/tests/modules/ds_test/css/dstest-2col-fluid.css
@@ -0,0 +1,10 @@
+
+.group-left {
+ float: left;
+ width: 50%;
+}
+
+.group-right {
+ float: left;
+ width: 50%;
+}
diff --git a/tests/modules/ds_test/ds_test.layouts.yml b/tests/modules/ds_test/ds_test.layouts.yml
index e501a24..3ca331e 100644
--- a/tests/modules/ds_test/ds_test.layouts.yml
+++ b/tests/modules/ds_test/ds_test.layouts.yml
@@ -19,3 +19,15 @@ dstest_2col:
label: Left
right:
label: Right
+dstest_2col_fluid:
+ label: Test Fluid two column
+ category: Display Suite
+ class: '\Drupal\ds\Plugin\DsLayout'
+ type: partial
+ template: templates/dstest-2col-fluid
+ css: css/dstest-2col-fluid.css
+ regions:
+ left:
+ label: Left
+ right:
+ label: Right
diff --git a/tests/modules/ds_test/templates/dstest-2col-fluid.html.twig b/tests/modules/ds_test/templates/dstest-2col-fluid.html.twig
new file mode 100644
index 0000000..4b64910
--- /dev/null
+++ b/tests/modules/ds_test/templates/dstest-2col-fluid.html.twig
@@ -0,0 +1,41 @@
+{#
+/**
+ * @file
+ * Display Suite fluid 2 column template.
+ *
+ * Available variables:
+ * - outer_wrapper: outer wrapper element
+ * - left_wrapper: wrapper element around left region
+ * - right_wrapper: wrapper element around right region
+ * - attributes: layout attributes
+ * - left_attributes: attributes for left region
+ * - right_attributes: attributes for right region
+ * - left: content of left region
+ * - right: content of right region
+ */
+#}
+
+{% set left = left|render %}
+{% set right = right|render %}
+
+{% if (left and not right) or (right and not left) %}
+ {% set layout_class = 'group-one-column' %}
+{% endif %}
+
+<{{ outer_wrapper }}{{ attributes.addClass(layout_class, 'ds-2col-fluid', 'clearfix') }}>
+
+ {{ title_suffix.contextual_links }}
+
+ {% if left %}
+ <{{ left_wrapper }}{{ left_attributes.addClass('group-left') }}>
+ {{ left }}
+ {{ left_wrapper }}>
+ {% endif %}
+
+ {% if right %}
+ <{{ right_wrapper }}{{ right_attributes.addClass('group-right') }}>
+ {{ right }}
+ {{ right_wrapper }}>
+ {% endif %}
+
+{{ outer_wrapper }}>