From fb839fa92272a09748fb21ae4af4ba22bd3ceeed Mon Sep 17 00:00:00 2001 From: Thilo Ratnaweera Date: Thu, 9 Feb 2017 10:40:32 +0100 Subject: [PATCH] Adressing https://github.com/neilime/zf2-twb-bundle/issues/191 making all format patterns overrideable. --- .../Form/View/Helper/TwbBundleForm.php | 4 ++-- .../Form/View/Helper/TwbBundleFormButton.php | 14 ++++++------- .../View/Helper/TwbBundleFormCollection.php | 4 ++-- .../Form/View/Helper/TwbBundleFormElement.php | 14 ++++++------- .../Form/View/Helper/TwbBundleFormRadio.php | 6 +++--- .../Form/View/Helper/TwbBundleFormRow.php | 12 +++++------ .../Form/View/Helper/TwbBundleFormStatic.php | 4 ++-- src/TwbBundle/View/Helper/TwbBundleAlert.php | 12 +++++------ src/TwbBundle/View/Helper/TwbBundleBadge.php | 8 ++++---- .../View/Helper/TwbBundleButtonGroup.php | 4 ++-- .../View/Helper/TwbBundleDropdown.php | 20 +++++++++---------- .../View/Helper/TwbBundleFontAwesome.php | 4 ++-- .../View/Helper/TwbBundleGlyphicon.php | 4 ++-- src/TwbBundle/View/Helper/TwbBundleLabel.php | 6 +++--- 14 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleForm.php b/src/TwbBundle/Form/View/Helper/TwbBundleForm.php index b2e739f..37130d5 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleForm.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleForm.php @@ -22,7 +22,7 @@ class TwbBundleForm extends Form /** * @var string */ - private static $formRowFormat = '
%s
'; + protected static $formRowFormat = '
%s
'; /** * Form layout (see LAYOUT_* consts) @@ -148,7 +148,7 @@ protected function renderElements(FormInterface $oForm, $sFormLayout = self::LAY } if ($bHasColumnSize && $sFormLayout !== self::LAYOUT_HORIZONTAL) { - $sFormContent = sprintf(self::$formRowFormat, $sFormContent); + $sFormContent = sprintf(static::$formRowFormat, $sFormContent); } return $sFormContent; } diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php index dea1d02..ad8d8fd 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php @@ -24,17 +24,17 @@ class TwbBundleFormButton extends FormButton /** * @var string */ - private static $dropdownContainerFormat = '
%s
'; + protected static $dropdownContainerFormat = '
%s
'; /** * @var string */ - private static $dropdownToggleFormat = '%s '; + protected static $dropdownToggleFormat = '%s '; /** * @var string */ - private static $dropdownCaretFormat = ''; + protected static $dropdownCaretFormat = ''; /** * Allowed button options @@ -61,7 +61,7 @@ public function render(ElementInterface $oElement, $sButtonContent = null) $sClass .= ' btn-default'; } else { $bHasOption = false; - foreach (self::$buttonOptions as $sButtonOption) { + foreach (static::$buttonOptions as $sButtonOption) { if (preg_match('/(\s|^)btn-' . $sButtonOption . '.*(\s|$)/', $sClass)) { $bHasOption = true; break; @@ -203,7 +203,7 @@ public function render(ElementInterface $oElement, $sButtonContent = null) */ $oElement->setAttribute('data-toggle', 'dropdown'); $sMarkup = $this->openTag($oElement) . - sprintf(self::$dropdownToggleFormat, $sButtonContent) . + sprintf(static::$dropdownToggleFormat, $sButtonContent) . $this->closeTag(); } else { /* @@ -212,7 +212,7 @@ public function render(ElementInterface $oElement, $sButtonContent = null) $sMarkup = $this->openTag($oElement) . $sButtonContent . $this->closeTag() . - sprintf(self::$dropdownCaretFormat, $oElement->getAttribute('class')); + sprintf(static::$dropdownCaretFormat, $oElement->getAttribute('class')); } /* @@ -226,7 +226,7 @@ public function render(ElementInterface $oElement, $sButtonContent = null) * Render button + dropdown */ return sprintf( - self::$dropdownContainerFormat, + static::$dropdownContainerFormat, //Drop way empty($aDropdownOptions['dropup']) ? '' : 'dropup', $sMarkup . diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php index 39b06d5..41d6f4e 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php @@ -79,7 +79,7 @@ public function render(ElementInterface $oElement) } $sMarkup = sprintf( - self::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel) + static::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel) ) . $sMarkup; } @@ -96,7 +96,7 @@ public function render(ElementInterface $oElement) } $sMarkup = sprintf( - self::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup + static::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup ); } return $sMarkup; diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php index dc52db7..a94cdd5 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php @@ -44,10 +44,10 @@ class TwbBundleFormElement extends FormElement implements TranslatorAwareInterfa * @var boolean */ protected $translatorEnabled = true; - + /** * Hold configurable options - * @var ModuleOptions + * @var ModuleOptions */ protected $options; @@ -66,7 +66,7 @@ class TwbBundleFormElement extends FormElement implements TranslatorAwareInterfa 'Zend\Form\Element\MonthSelect' => 'formmonthselect', 'TwbBundle\Form\Element\StaticElement' => 'formStatic', ); - + public function __construct(ModuleOptions $options) { if (is_array($options->getTypeMap())) { @@ -122,7 +122,7 @@ public function render(ElementInterface $oElement) } } return sprintf( - self::$inputGroupFormat, + static::$inputGroupFormat, trim($sSpecialClass), $sMarkup ); @@ -181,12 +181,12 @@ protected function renderAddOn($aAddOnOptions) is_object($aAddOnOptions['element']) ? get_class($aAddOnOptions['element']) : gettype($aAddOnOptions['element']) )); } - + $aAddOnOptions['element']->setOptions(array_merge( $aAddOnOptions['element']->getOptions(), array('disable-twb' => true) )); - + $sMarkup .= $this->render($aAddOnOptions['element']); //Element is a button, so add-on container must be a "div" @@ -198,7 +198,7 @@ protected function renderAddOn($aAddOnOptions) } } - return sprintf(self::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName); + return sprintf(static::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName); } /** diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php index 4b5f040..031fae2 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php @@ -18,7 +18,7 @@ class TwbBundleFormRadio extends FormRadio /** * @var string */ - private static $checkboxFormat = '
%s
'; + protected static $checkboxFormat = '
%s
'; /** * @see \Zend\Form\View\Helper\FormRadio::render() @@ -43,7 +43,7 @@ public function render(ElementInterface $oElement) $oElement->setLabelAttributes(array('class' => 'radio-inline')); $sReturn = sprintf('%s', parent::render($oElement)); $this->setSeparator($sSeparator); - return $sReturn; + return $sReturn; } if (isset($aElementOptions['btn-group']) && $aElementOptions['btn-group'] == true) { @@ -53,7 +53,7 @@ public function render(ElementInterface $oElement) return sprintf('
%s
', parent::render($oElement)); } - return sprintf(self::$checkboxFormat, parent::render($oElement)); + return sprintf(static::$checkboxFormat, parent::render($oElement)); } /** diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php index a57b5fb..ebd1c66 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php @@ -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) . "\n"; + return sprintf(static::$formGroupFormat, $sRowClass, $sElementContent) . "\n"; } /** @@ -270,7 +270,7 @@ protected function renderElement(ElementInterface $oElement, $sLabelPosition = n // Checkbox elements are a special case, element is already rendered into label if ($sElementType === 'checkbox') { - $sElementContent = sprintf(self::$checkboxFormat, $sElementContent); + $sElementContent = sprintf(static::$checkboxFormat, $sElementContent); } else { if ($sLabelPosition === self::LABEL_PREPEND) { $sElementContent = $sLabelOpen . $sLabelContent . $sLabelClose . $sElementContent; @@ -307,17 +307,17 @@ protected function renderElement(ElementInterface $oElement, $sLabelPosition = n // Checkbox elements are a special case, element is rendered into label if ($sElementType === 'checkbox') { return sprintf( - self::$horizontalLayoutFormat, $sClass, sprintf(self::$checkboxFormat, $sElementContent) + static::$horizontalLayoutFormat, $sClass, sprintf(static::$checkboxFormat, $sElementContent) ); } if ($sLabelPosition === self::LABEL_PREPEND) { return $sLabelOpen . $sLabelContent . $sLabelClose . sprintf( - self::$horizontalLayoutFormat, $sClass, $sElementContent + static::$horizontalLayoutFormat, $sClass, $sElementContent ); } else { return sprintf( - self::$horizontalLayoutFormat, $sClass, $sElementContent + static::$horizontalLayoutFormat, $sClass, $sElementContent ) . $sLabelOpen . $sLabelContent . $sLabelClose; } } @@ -339,7 +339,7 @@ protected function renderHelpBlock(ElementInterface $oElement) if ($sHelpBlock === $sHelpBlockString) { $sHelpBlock = $this->getEscapeHtmlHelper()->__invoke($sHelpBlock); } - return sprintf(self::$helpBlockFormat, $sHelpBlock); + return sprintf(static::$helpBlockFormat, $sHelpBlock); } else { return ''; } diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php index 1a33af8..926b1c0 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php @@ -9,7 +9,7 @@ class TwbBundleFormStatic extends AbstractHelper /** * @var string */ - private static $staticFormat = '

%s

'; + protected static $staticFormat = '

%s

'; /** * Invoke helper as functor @@ -35,6 +35,6 @@ public function __invoke(ElementInterface $element = null) */ public function render(ElementInterface $oElement) { - return sprintf(self::$staticFormat, $oElement->getValue()); + return sprintf(static::$staticFormat, $oElement->getValue()); } } diff --git a/src/TwbBundle/View/Helper/TwbBundleAlert.php b/src/TwbBundle/View/Helper/TwbBundleAlert.php index c28e604..4cb56ad 100644 --- a/src/TwbBundle/View/Helper/TwbBundleAlert.php +++ b/src/TwbBundle/View/Helper/TwbBundleAlert.php @@ -10,12 +10,12 @@ class TwbBundleAlert extends AbstractHelper /** * @var string */ - private static $alertFormat = '
%s
'; + protected static $alertFormat = '
%s
'; /** * @var string */ - private static $dismissButtonFormat = ''; + protected static $dismissButtonFormat = ''; /** * Invoke helper as functor, proxies to {@link render()}. @@ -48,7 +48,7 @@ public function render($sAlertMessage, $aAlertAttributes = null, $bDismissable = if (!is_scalar($sAlertMessage)) { throw new InvalidArgumentException('Alert message expects a scalar value, "' . gettype($sAlertMessage) . '" given'); } - + if (empty($aAlertAttributes)) { $aAlertAttributes = array('class' => 'alert'); } elseif (is_string($aAlertAttributes)) { @@ -64,20 +64,20 @@ public function render($sAlertMessage, $aAlertAttributes = null, $bDismissable = if (!preg_match('/(\s|^)alert(\s|$)/', $aAlertAttributes['class'])) { $aAlertAttributes['class'] .= ' alert'; } - + if (null !== ($oTranslator = $this->getTranslator())) { $sAlertMessage = $oTranslator->translate($sAlertMessage, $this->getTranslatorTextDomain()); } if ($bDismissable) { - $sAlertMessage = self::$dismissButtonFormat . $sAlertMessage; + $sAlertMessage = static::$dismissButtonFormat . $sAlertMessage; if (!preg_match('/(\s|^)alert-dismissable(\s|$)/', $aAlertAttributes['class'])) { $aAlertAttributes['class'] .= ' alert-dismissable'; } } return sprintf( - self::$alertFormat, + static::$alertFormat, $this->createAttributesString($aAlertAttributes), $sAlertMessage ); diff --git a/src/TwbBundle/View/Helper/TwbBundleBadge.php b/src/TwbBundle/View/Helper/TwbBundleBadge.php index 9460433..ab95a41 100644 --- a/src/TwbBundle/View/Helper/TwbBundleBadge.php +++ b/src/TwbBundle/View/Helper/TwbBundleBadge.php @@ -10,7 +10,7 @@ class TwbBundleBadge extends AbstractHelper /** * @var string */ - private static $badgeFormat = '%s'; + protected static $badgeFormat = '%s'; /** * Invoke helper as functor, proxies to {@link render()}. @@ -51,13 +51,13 @@ public function render($sBadgeMessage, array $aBadgeAttributes = null) $aBadgeAttributes['class'] .= ' badge'; } } - + if (null !== ($oTranslator = $this->getTranslator())) { $sBadgeMessage = $oTranslator->translate($sBadgeMessage, $this->getTranslatorTextDomain()); } - + return sprintf( - self::$badgeFormat, + static::$badgeFormat, $this->createAttributesString($aBadgeAttributes), $sBadgeMessage ); diff --git a/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php b/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php index ddeb248..e92236a 100644 --- a/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php +++ b/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php @@ -64,7 +64,7 @@ public function render(array $aButtons, array $aButtonGroupOptions = null) * Render button group */ return sprintf( - self::$buttonGroupContainerFormat, + static::$buttonGroupContainerFormat, //Container attributes $this->createAttributesString($aButtonGroupOptions['attributes']), //Buttons @@ -98,7 +98,7 @@ protected function renderButtons(array $aButtons, $bJustified = false) $sButtonMarkup = $this->getFormElementHelper()->__invoke($oButton); - $sMarkup .= $bJustified ? sprintf(self::$buttonGroupJustifiedFormat, $sButtonMarkup) : $sButtonMarkup; + $sMarkup .= $bJustified ? sprintf(static::$buttonGroupJustifiedFormat, $sButtonMarkup) : $sButtonMarkup; } return $sMarkup; } diff --git a/src/TwbBundle/View/Helper/TwbBundleDropdown.php b/src/TwbBundle/View/Helper/TwbBundleDropdown.php index ab3665f..1a4e47b 100644 --- a/src/TwbBundle/View/Helper/TwbBundleDropdown.php +++ b/src/TwbBundle/View/Helper/TwbBundleDropdown.php @@ -27,27 +27,27 @@ class TwbBundleDropDown extends AbstractHelper /** * @var string */ - private static $dropdownContainerFormat = '
%s
'; + protected static $dropdownContainerFormat = '
%s
'; /** * @var string */ - private static $dropdownToggleFormat = '%s '; + protected static $dropdownToggleFormat = '%s '; /** * @var string */ - private static $dropdownListFormat = ''; + protected static $dropdownListFormat = ''; /** * @var string */ - private static $dropdownItemContainerFormat = '
  • %s
  • '; + protected static $dropdownItemContainerFormat = '
  • %s
  • '; /** * @var string */ - private static $dropdownItemFormats = array( + protected static $dropdownItemFormats = array( self::TYPE_ITEM_LINK => '%s', ); @@ -88,7 +88,7 @@ public function render(array $aDropdownOptions) // Render dropdown return sprintf( - self::$dropdownContainerFormat, $this->createAttributesString($aDropdownOptions['attributes']), //Container attributes + static::$dropdownContainerFormat, $this->createAttributesString($aDropdownOptions['attributes']), //Container attributes $this->renderToggle($aDropdownOptions) . //Toggle $this->renderListItems($aDropdownOptions) //List items ); @@ -157,7 +157,7 @@ public function renderToggle(array $aDropdownOptions) $this->validTagAttributes = $aValidTagAttributes; return sprintf( - self::$dropdownToggleFormat, $sAttributeString, // Toggle attributes + static::$dropdownToggleFormat, $sAttributeString, // Toggle attributes $this->getEscapeHtmlHelper()->__invoke($aDropdownOptions['label']) // Toggle label ); } @@ -232,7 +232,7 @@ public function renderListItems(array $aDropdownOptions) } return sprintf( - self::$dropdownListFormat, $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes + static::$dropdownListFormat, $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes $sItems // Items ); } @@ -325,10 +325,10 @@ protected function renderItem($aItemOptions) $sAttributeString = $this->createAttributesString($aItemOptions['item_attributes']); $this->validTagAttributes = $aValidTagAttributes; - $sItemContent = sprintf(self::$dropdownItemFormats[self::TYPE_ITEM_LINK], $sAttributeString, $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label'])); + $sItemContent = sprintf(static::$dropdownItemFormats[self::TYPE_ITEM_LINK], $sAttributeString, $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label'])); break; } - return sprintf(self::$dropdownItemContainerFormat, $this->createAttributesString($aItemOptions['attributes']), $sItemContent); + return sprintf(static::$dropdownItemContainerFormat, $this->createAttributesString($aItemOptions['attributes']), $sItemContent); } } diff --git a/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php b/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php index ed3102f..1e15505 100644 --- a/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php +++ b/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php @@ -19,7 +19,7 @@ class TwbBundleFontAwesome extends AbstractHelper /** * @var string */ - private static $faFormat = ''; + protected static $faFormat = ''; /** * Invoke helper as functor, proxies to {@link render()}. @@ -73,7 +73,7 @@ public function render($sFontAwesome, array $aFontAwesomeAttributes = null) } return sprintf( - self::$faFormat, + static::$faFormat, $this->createAttributesString($aFontAwesomeAttributes) ); } diff --git a/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php b/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php index 2fe07ff..07ebe8c 100644 --- a/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php +++ b/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php @@ -10,7 +10,7 @@ class TwbBundleGlyphicon extends AbstractHelper /** * @var string */ - private static $glyphiconFormat = ''; + protected static $glyphiconFormat = ''; /** * Invoke helper as functor, proxies to {@link render()}. @@ -59,7 +59,7 @@ public function render($sGlyphicon, array $aGlyphiconAttributes = null) } return sprintf( - self::$glyphiconFormat, + static::$glyphiconFormat, $this->createAttributesString($aGlyphiconAttributes) ); } diff --git a/src/TwbBundle/View/Helper/TwbBundleLabel.php b/src/TwbBundle/View/Helper/TwbBundleLabel.php index dd179a9..a5c58a8 100644 --- a/src/TwbBundle/View/Helper/TwbBundleLabel.php +++ b/src/TwbBundle/View/Helper/TwbBundleLabel.php @@ -13,7 +13,7 @@ class TwbBundleLabel extends AbstractHelper /** * @var string */ - private static $labelFormat = '<%s %s>%s'; + protected static $labelFormat = '<%s %s>%s'; /** * @var string @@ -38,7 +38,7 @@ public function __invoke($sLabelMessage = null, $aLabelAttributes = 'label-defau if (!$sLabelMessage) { return $this; } - + return $this->render($sLabelMessage, $aLabelAttributes); } @@ -78,7 +78,7 @@ public function render($sLabelMessage, $aLabelAttributes = 'label-default') } return sprintf( - self::$labelFormat, + static::$labelFormat, isset($aLabelAttributes['tagName']) ? $aLabelAttributes['tagName'] : $this->tagName, $this->createAttributesString($aLabelAttributes), $sLabelMessage