Skip to content

Commit

Permalink
Merge pull request #11 from Syberon/fix-form-element-helper
Browse files Browse the repository at this point in the history
Fix incorrect element render in FormElement
  • Loading branch information
neilime authored Feb 9, 2019
2 parents 18cf759 + 892b68f commit 725e821
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/TwbsHelper/Form/View/Helper/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
class FormElement extends ZendFormElementViewHelper implements TranslatorAwareInterface
{
// @var string
protected static $addonFormat = '<%s class="%s" %s><span class="input-group-text">%s</span></%s>';
protected static $addonFormat = '<%s class="%s" %s>%s</%s>';

// @var string
protected static $addonTextFormat = '<span class="input-group-text">%s</span>';

// @var string
protected static $inputGroupFormat = '<div class="input-group %s" %s>%s</div>';
Expand Down Expand Up @@ -194,7 +197,7 @@ protected function renderAddOn($aAddOnOptions, string $sPosition = 'prepend')

$sMarkup = '';
$sAddonTagName = 'div';
$sAddonClass = '';
$sAddonClass = ('prepend' == $sPosition) ? ' input-group-prepend' : 'input-group-append';

if (! empty($aAddOnOptions['text'])) {
if (! is_scalar($aAddOnOptions['text'])) {
Expand All @@ -203,12 +206,11 @@ protected function renderAddOn($aAddOnOptions, string $sPosition = 'prepend')
is_object($aAddOnOptions['text']) ? get_class($aAddOnOptions['text']) : gettype($aAddOnOptions['text'])
));
} elseif (($oTranslator = $this->getTranslator())) {
$sMarkup .= $oTranslator->translate($aAddOnOptions['text'], $this->getTranslatorTextDomain());
$sMarkup .= sprintf(static::$addonTextFormat, $oTranslator->translate($aAddOnOptions['text'], $this->getTranslatorTextDomain()));
} else {
$sMarkup .= $aAddOnOptions['text'];
$sMarkup .= sprintf(static::$addonTextFormat, $aAddOnOptions['text']);
}

$sAddonClass .= ('prepend' == $sPosition) ? ' input-group-prepend' : 'input-group-append';
} elseif (! empty($aAddOnOptions['element'])) {
if (is_array($aAddOnOptions['element']) ||
($aAddOnOptions['element'] instanceof Traversable &&
Expand All @@ -229,14 +231,6 @@ protected function renderAddOn($aAddOnOptions, string $sPosition = 'prepend')
));

$sMarkup .= $this->render($aAddOnOptions['element']);

//Element is a button, so add-on container must be a "div"
if ($aAddOnOptions['element'] instanceof Button) {
$sAddonClass .= ' input-group-btn';
$sAddonTagName = 'div';
} else {
$sAddonClass .= ' input-group-addon';
}
}

$sAttributes = '';
Expand Down

0 comments on commit 725e821

Please sign in to comment.