Skip to content

Commit

Permalink
Merge pull request #7 from matusmark/patch-4
Browse files Browse the repository at this point in the history
Update FormElement.php
  • Loading branch information
neilime authored Sep 7, 2018
2 parents d5a3b51 + 25607bc commit a13e371
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/TwbsHelper/Form/View/Helper/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
class FormElement extends ZendFormElementViewHelper implements TranslatorAwareInterface
{
// @var string
protected static $addonFormat = '<%s class="%s"><span class="input-group-text">%s</span></%s>';
protected static $addonFormat = '<%s class="%s" %s><span class="input-group-text">%s</span></%s>';

// @var string
protected static $inputGroupFormat = '<div class="input-group %s">%s</div>';
protected static $inputGroupFormat = '<div class="input-group %s" %s>%s</div>';

// Translator (optional)
// @var Translator
Expand Down Expand Up @@ -114,7 +114,7 @@ public function render(ElementInterface $oElement)

// Addon append
if ($aAddOnAppend = $oElement->getOption('add-on-append')) {
$sMarkup .= $this->renderAddOn($aAddOnAppend);
$sMarkup .= $this->renderAddOn($aAddOnAppend, 'append');
}

if ($aAddOnAppend || $aAddOnPrepend) {
Expand All @@ -128,11 +128,34 @@ public function render(ElementInterface $oElement)
$sSpecialClass .= ' input-group-sm';
}
}


$sSpecialAttributes = '';

// Input group attributes
if (is_array($oElement->getOption('input-group'))){
$aInputGroup = $oElement->getOption('input-group');

// Input group class
if(! empty($aInputGroup['class'])){
$sSpecialClass .= ' ' . $aInputGroup['class'];
}

// Input group other attributes
if(is_array($aInputGroup['attributes'])){
foreach ($aInputGroup['attributes'] as $name => $value){
$sSpecialAttributes .= $name . '="' . $value . '" ';
}
$sSpecialAttributes = trim($sSpecialAttributes);
}

}

// Add a sprintf directive for correct render of errors
return $sMarkup = sprintf(
static::$inputGroupFormat,
trim($sSpecialClass),
$sSpecialAttributes,
$sMarkup . "%s"
);
}
Expand Down Expand Up @@ -222,8 +245,17 @@ protected function renderAddOn($aAddOnOptions, string $sPosition = 'prepend')
$sAddonClass .= ' input-group-addon';
}
}

$sAttributes = '';

if(! empty($aAddOnOptions['attributes'])){
foreach($aAddOnOptions['attributes'] as $name => $value){
$sAttributes .= $name .'="' . $value . '" ';
}
$sAttributes = rtrim($sAttributes);
}

return sprintf(static::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName);
return sprintf(static::$addonFormat, $sAddonTagName, trim($sAddonClass), $sAttributes, $sMarkup, $sAddonTagName);
}


Expand Down

0 comments on commit a13e371

Please sign in to comment.