Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #190 from alexz707/master
Browse files Browse the repository at this point in the history
Ability to show label in inline-form including change from \r\n to \n
  • Loading branch information
neilime authored Jan 29, 2017
2 parents 6c762a9 + ed42211 commit 7bfa5ad
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/TwbBundle/Form/View/Helper/TwbBundleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function render(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZON
$oForm->setAttribute('role', 'form');
}

return $this->openTag($oForm) . PHP_EOL . $this->renderElements($oForm, $sFormLayout) . $this->closeTag();
return $this->openTag($oForm) . "\n" . $this->renderElements($oForm, $sFormLayout) . $this->closeTag();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public function render(ElementInterface $oElement)
$sMarkup .= $oFieldsetHelper($oElementOrFieldset);
} elseif ($oElementOrFieldset instanceof \Zend\Form\ElementInterface) {
if ($oElementOrFieldset->getOption('twb-row-open')) {
$sMarkup .= '<div class="row">' . PHP_EOL;
$sMarkup .= '<div class="row">' . "\n";
}

$sMarkup .= $oElementHelper($oElementOrFieldset);

if ($oElementOrFieldset->getOption('twb-row-close')) {
$sMarkup .= '</div>' . PHP_EOL;
$sMarkup .= '</div>' . "\n";
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function render(ElementInterface $oElement, $sLabelPosition = null)
case $sElementType === 'checkbox' && $sLayout !== TwbBundleForm::LAYOUT_HORIZONTAL && !$oElement->getOption('form-group'):
// All "button" elements in inline form
case in_array($sElementType, array('submit', 'button', 'reset'), true) && $sLayout === TwbBundleForm::LAYOUT_INLINE:
return $sElementContent . PHP_EOL;
return $sElementContent . "\n";
default:
// Render element into form group
return $this->renderElementFormGroup($sElementContent, $this->getRowClassFromElement($oElement));
Expand Down Expand Up @@ -153,7 +153,7 @@ public function renderElementFormGroup($sElementContent, $sRowClass)
if (!is_string($sRowClass)) {
throw new \InvalidArgumentException('Argument "$sRowClass" expects a string, "' . (is_object($sRowClass) ? get_class($sRowClass) : gettype($sRowClass)) . '" given');
}
return sprintf(self::$formGroupFormat, $sRowClass, $sElementContent) . PHP_EOL;
return sprintf(self::$formGroupFormat, $sRowClass, $sElementContent) . "\n";
}

/**
Expand Down Expand Up @@ -216,10 +216,12 @@ protected function renderElement(ElementInterface $oElement, $sLabelPosition = n
//Hide label for "inline" layout
case TwbBundleForm::LAYOUT_INLINE:
if ($sElementType !== 'checkbox') {
if (empty($aLabelAttributes['class'])) {
$aLabelAttributes['class'] = 'sr-only';
} elseif (!preg_match('/(\s|^)sr-only(\s|$)/', $aLabelAttributes['class'])) {
$aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' sr-only');
if ($sElementType !== 'checkbox') {
if (empty($aLabelAttributes['class']) && empty($oElement->getOption('showLabel'))) {
$aLabelAttributes['class'] = 'sr-only';
} elseif (empty($oElement->getOption('showLabel')) && !preg_match('/(\s|^)sr-only(\s|$)/', $aLabelAttributes['class'])) {
$aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' sr-only');
}
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/TwbBundle/View/Helper/TwbBundleDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function renderListItems(array $aDropdownOptions)
$aItemOptions['type'] = self::TYPE_ITEM_LINK;
}
}
$sItems .= $this->renderItem($aItemOptions) . PHP_EOL;
$sItems .= $this->renderItem($aItemOptions) . "\n";
}

return sprintf(
Expand Down
10 changes: 5 additions & 5 deletions tests/TwbBundleTest/BootstrapBasedTests/TwbBundleAlertsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public function testExamples(){
$sContent = '';

//Success
$sContent .= $this->alertHelper->__invoke('<strong>Well done!</strong> You successfully read this important alert message.','alert-success').PHP_EOL;
$sContent .= $this->alertHelper->__invoke('<strong>Well done!</strong> You successfully read this important alert message.','alert-success')."\n";

//Info
$sContent .= $this->alertHelper->__invoke('<strong>Heads up!</strong> This alert needs your attention, but it\'s not super important.','alert-info').PHP_EOL;
$sContent .= $this->alertHelper->__invoke('<strong>Heads up!</strong> This alert needs your attention, but it\'s not super important.','alert-info')."\n";

//Warning
$sContent .= $this->alertHelper->__invoke('<strong>Warning!</strong> Best check yo self, you\'re not looking too good.','alert-warning').PHP_EOL;
$sContent .= $this->alertHelper->__invoke('<strong>Warning!</strong> Best check yo self, you\'re not looking too good.','alert-warning')."\n";

//Danger
$sContent .= $this->alertHelper->__invoke('<strong>Oh snap!</strong> Change a few things up and try submitting again.','alert-danger').PHP_EOL;
$sContent .= $this->alertHelper->__invoke('<strong>Oh snap!</strong> Change a few things up and try submitting again.','alert-danger')."\n";

$this->assertStringEqualsFile($this->expectedPath.'alerts-examples.phtml',$sContent);
}
Expand All @@ -51,7 +51,7 @@ public function testExamples(){
*/
public function testDismissableAlerts(){

$sContent = $this->alertHelper->__invoke('<strong>Warning!</strong> Best check yo self, you\'re not looking too good.',null,true).PHP_EOL;
$sContent = $this->alertHelper->__invoke('<strong>Warning!</strong> Best check yo self, you\'re not looking too good.',null,true)."\n";

$this->assertStringEqualsFile($this->expectedPath.'alerts-dismissable.phtml',$sContent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function testBadges(){
$sContent = '';

//Default
$sContent .= $this->badgeHelper->__invoke('42').PHP_EOL;
$sContent .= $this->badgeHelper->__invoke('42')."\n";

//Pull-right
$sContent .= $this->badgeHelper->__invoke('3',array('class' => 'pull-right')).PHP_EOL;
$sContent .= $this->badgeHelper->__invoke('3',array('class' => 'pull-right'))."\n";

$this->assertStringEqualsFile($this->expectedPath.'badges.phtml',$sContent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ public function testSingleButtonDropdowns() {

$sContent = '';
$oButton = new \Zend\Form\Element\Button('default', array('label' => 'Default', 'dropdown' => $aDropDownOptions));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('primary', array('label' => 'Primary', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-primary');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('success', array('label' => 'Success', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-success');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('info', array('label' => 'Info', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-info');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('warning', array('label' => 'Warning', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-warning');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('danger', array('label' => 'Danger', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-danger');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'dropdowns-single.phtml', $sContent);
Expand All @@ -76,27 +76,27 @@ public function testSplitButtonDropdowns() {
$sContent = '';

$oButton = new \Zend\Form\Element\Button('default', array('label' => 'Default', 'dropdown' => $aDropDownOptions));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('primary', array('label' => 'Primary', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-primary');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('success', array('label' => 'Success', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-success');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('info', array('label' => 'Info', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-info');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('warning', array('label' => 'Warning', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-warning');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('danger', array('label' => 'Danger', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-danger');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'dropdowns-split.phtml', $sContent);
Expand All @@ -115,17 +115,17 @@ public function testDropdownsSizing() {
//Large
$oButton = new \Zend\Form\Element\Button('large-button-default', array('label' => 'Large button', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-lg');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Small
$oButton = new \Zend\Form\Element\Button('small-button-default', array('label' => 'Small button', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-sm');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Extra small
$oButton = new \Zend\Form\Element\Button('extra-small-button-default', array('label' => 'Extra small button', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-xs');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'dropdowns-sizing.phtml', $sContent);
Expand All @@ -144,12 +144,12 @@ public function testDropup() {
$sContent = '';

$oButton = new \Zend\Form\Element\Button('default', array('label' => 'Dropup', 'dropdown' => $aDropDownOptions));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$aDropDownOptions['list_attributes'] = array('class' => 'pull-right');
$oButton = new \Zend\Form\Element\Button('primary', array('label' => 'Right dropup', 'dropdown' => $aDropDownOptions));
$oButton->setAttribute('class', 'btn-primary');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'dropup.phtml', $sContent);
Expand Down
42 changes: 21 additions & 21 deletions tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ public function setUp() {
public function testButtonsOptions() {
$sContent = '';
$oButton = new \Zend\Form\Element\Button('default', array('label' => 'Default'));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('primary', array('label' => 'Primary'));
$oButton->setAttribute('class', 'btn-primary');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('success', array('label' => 'Success'));
$oButton->setAttribute('class', 'btn-success');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('info', array('label' => 'Info'));
$oButton->setAttribute('class', 'btn-info');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('warning', array('label' => 'Warning'));
$oButton->setAttribute('class', 'btn-warning');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('danger', array('label' => 'Danger'));
$oButton->setAttribute('class', 'btn-danger');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('link', array('label' => 'Link'));
$oButton->setAttribute('class', 'btn-link');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'options.phtml', $sContent);
Expand All @@ -73,46 +73,46 @@ public function testButtonsSizes() {
//Large
$oButton = new \Zend\Form\Element\Button('large-button-primary', array('label' => 'Large button'));
$oButton->setAttribute('class', 'btn-primary btn-lg');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('large-button-default', array('label' => 'Large button'));
$oButton->setAttribute('class', 'btn-lg');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Default
$oButton = new \Zend\Form\Element\Button('button-primary', array('label' => 'Default button'));
$oButton->setAttribute('class', 'btn-primary');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('button-default', array('label' => 'Default button'));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Small
$oButton = new \Zend\Form\Element\Button('small-button-primary', array('label' => 'Small button'));
$oButton->setAttribute('class', 'btn-primary btn-sm');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('small-button-default', array('label' => 'Small button'));
$oButton->setAttribute('class', 'btn-sm');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Extra small
$oButton = new \Zend\Form\Element\Button('extra-small-button-primary', array('label' => 'Extra small button'));
$oButton->setAttribute('class', 'btn-primary btn-xs');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('extra-small-button-default', array('label' => 'Extra small button'));
$oButton->setAttribute('class', 'btn-xs');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Block level
$oButton = new \Zend\Form\Element\Button('block-level-button-primary', array('label' => 'Block level button'));
$oButton->setAttribute('class', 'btn-primary btn-block');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('block-level-button-default', array('label' => 'Block level button'));
$oButton->setAttribute('class', 'btn-block');
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'sizes.phtml', $sContent);
Expand All @@ -128,13 +128,13 @@ public function testButtonsActive() {
$oButton->setAttributes(array(
'class' => 'btn-primary btn-lg active',
));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('large-button-default-active', array('label' => 'Button'));
$oButton->setAttributes(array(
'class' => 'btn-lg active',
));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'active.phtml', $sContent);
Expand All @@ -151,14 +151,14 @@ public function testButtonsDisabled() {
'class' => 'btn-primary btn-lg',
'disabled' => true
));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

$oButton = new \Zend\Form\Element\Button('large-button-default-disabled', array('label' => 'Button'));
$oButton->setAttributes(array(
'class' => 'btn-lg',
'disabled' => true
));
$sContent .= $this->formButtonHelper->__invoke($oButton) . PHP_EOL;
$sContent .= $this->formButtonHelper->__invoke($oButton) . "\n";

//Test content
$this->assertStringEqualsFile($this->expectedPath . 'disabled.phtml', $sContent);
Expand Down
Loading

0 comments on commit 7bfa5ad

Please sign in to comment.