From 6a6c13e57fcedbd341f665dace3c68539cdccab6 Mon Sep 17 00:00:00 2001 From: Moritz Fain Date: Mon, 14 Nov 2016 11:14:25 +0100 Subject: [PATCH 1/2] Added ability to add custom row class --- src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php | 5 +++++ .../Form/View/Helper/TwbBundleFormRowTest.php | 13 +++++++++++++ tests/_files/expected-rows/row-class.phtml | 1 + 3 files changed, 19 insertions(+) create mode 100644 tests/_files/expected-rows/row-class.phtml diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php index 33c2681..e70e180 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php @@ -131,6 +131,11 @@ public function getRowClassFromElement(\Zend\Form\ElementInterface $oElement) ) { $sRowClass .= ' col-' . $sColumSize; } + + //Additional row class + if ($sAddRowClass = $oElement->getOption('twb-row-class')) { + $sRowClass .= ' ' . $sAddRowClass; + } return $sRowClass; } diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php index fb01300..fd3760e 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php @@ -163,6 +163,19 @@ public function testRenderRadiosWithHorizontalLayout() $this->assertStringEqualsFile($this->expectedPath . 'radio-horizontal-layout.phtml', $this->formRowHelper->__invoke($oElement)); } + public function testRenderFormRowWithSpecificClass() + { + $oElement = new \Zend\Form\Element\Text('test-text', array( + 'label' => 'Test text', + 'column-size' => 'sm-10', + 'label_attributes' => array('class' => 'col-sm-2'), + 'twb-row-class' => 'my-row-class' + )); + + // Test content + $this->assertStringEqualsFile($this->expectedPath . 'row-class.phtml', $this->formRowHelper->__invoke($oElement)); + } + public function testRenderInputWithHelpTextAndError() { $oElement = new \Zend\Form\Element\Text('input-text', array( diff --git a/tests/_files/expected-rows/row-class.phtml b/tests/_files/expected-rows/row-class.phtml new file mode 100644 index 0000000..5f3ebca --- /dev/null +++ b/tests/_files/expected-rows/row-class.phtml @@ -0,0 +1 @@ +
From 03d91e456693f208dc2b3e659637812b6fda2f0a Mon Sep 17 00:00:00 2001 From: Moritz Fain Date: Mon, 14 Nov 2016 12:55:53 +0100 Subject: [PATCH 2/2] Added ability to add custom row class (updated README.md) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cc4638c..b835ee9 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,7 @@ The option `twb-layout` (string) can be passed to the element to render the row The option `validation-state` (string) can be passed to the element to render the row with a defined validation state class attribute(`has-...`). If the element has messages, `has-error` class attribute is auto added. The option `column-size` (int) can be passed to the element to render the row with a defined column size class attribute(`col-lg-...`). The option `help-block` (string) can be passed to the element to render an help block translated appending the element. +The option `twb-row-class` (string) can be passed to the element to render the row with an additional class. If you like to wrap elements into a
in case you want X number of elements on the same line the option `twb-row-open` (bool) can be passed to the element where the row must start and will be printed before the element is rendered. It could be you have to provide the `column-size` in combination with this option. The option `twb-row-close` (bool) can be passed to the element to close the earlier opened row and will be printed after the elements is rendered.