From 892b68f6f1e49b67aac87c9eb6b15e9ff89c07a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A7=D0=B5=D1=88?= =?UTF-8?q?=D1=83=D0=B8=D0=BD?= Date: Fri, 8 Feb 2019 15:49:18 +0700 Subject: [PATCH] Fix incorrect element render in FormElement Fix incorrect render of input-group-append/prepend element in FormElement view helper. In last version of FormElement helper there are incorrect render of input groups containing elements: Checkboxes, radis etc:
Buttons:
These structures and classes 'input-group-addon/input-group-btn' were used only in the alpha version and removed in release version of Bootstrap 4. Correct output should be like: For all active elements (Buttons, checkboxes etc)
//or 'input-group-prepend'
And for only text addons:
//or 'input-group-prepend' some text
--- .../Form/View/Helper/FormElement.php | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/TwbsHelper/Form/View/Helper/FormElement.php b/src/TwbsHelper/Form/View/Helper/FormElement.php index 7424d1e21..7d0a6a732 100644 --- a/src/TwbsHelper/Form/View/Helper/FormElement.php +++ b/src/TwbsHelper/Form/View/Helper/FormElement.php @@ -24,7 +24,10 @@ class FormElement extends ZendFormElementViewHelper implements TranslatorAwareInterface { // @var string - protected static $addonFormat = '<%s class="%s" %s>%s'; + protected static $addonFormat = '<%s class="%s" %s>%s'; + + // @var string + protected static $addonTextFormat = '%s'; // @var string protected static $inputGroupFormat = '
%s
'; @@ -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'])) { @@ -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 && @@ -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 = '';