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 #192 from netbrothers-tr/master
Browse files Browse the repository at this point in the history
Adressing #191 making all format patterns overrideable.
  • Loading branch information
neilime authored Feb 9, 2017
2 parents 7bfa5ad + fb839fa commit aac9657
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/TwbBundle/Form/View/Helper/TwbBundleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TwbBundleForm extends Form
/**
* @var string
*/
private static $formRowFormat = '<div class="row">%s</div>';
protected static $formRowFormat = '<div class="row">%s</div>';

/**
* Form layout (see LAYOUT_* consts)
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class TwbBundleFormButton extends FormButton
/**
* @var string
*/
private static $dropdownContainerFormat = '<div class="btn-group %s">%s</div>';
protected static $dropdownContainerFormat = '<div class="btn-group %s">%s</div>';

/**
* @var string
*/
private static $dropdownToggleFormat = '%s <b class="caret"></b>';
protected static $dropdownToggleFormat = '%s <b class="caret"></b>';

/**
* @var string
*/
private static $dropdownCaretFormat = '<button type="button" class="dropdown-toggle %s" data-toggle="dropdown"><span class="caret"></span></button>';
protected static $dropdownCaretFormat = '<button type="button" class="dropdown-toggle %s" data-toggle="dropdown"><span class="caret"></span></button>';

/**
* Allowed button options
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
/*
Expand All @@ -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'));
}

/*
Expand All @@ -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 .
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 @@ -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;
}

Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class TwbBundleFormElement extends FormElement implements TranslatorAwareInterfa
* @var boolean
*/
protected $translatorEnabled = true;

/**
* Hold configurable options
* @var ModuleOptions
* @var ModuleOptions
*/
protected $options;

Expand All @@ -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())) {
Expand Down Expand Up @@ -122,7 +122,7 @@ public function render(ElementInterface $oElement)
}
}
return sprintf(
self::$inputGroupFormat,
static::$inputGroupFormat,
trim($sSpecialClass),
$sMarkup
);
Expand Down Expand Up @@ -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"
Expand All @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TwbBundleFormRadio extends FormRadio
/**
* @var string
*/
private static $checkboxFormat = '<div class="radio">%s</div>';
protected static $checkboxFormat = '<div class="radio">%s</div>';

/**
* @see \Zend\Form\View\Helper\FormRadio::render()
Expand All @@ -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) {
Expand All @@ -53,7 +53,7 @@ public function render(ElementInterface $oElement)
return sprintf('<div class="btn-group" data-toggle="buttons">%s</div>', parent::render($oElement));
}

return sprintf(self::$checkboxFormat, parent::render($oElement));
return sprintf(static::$checkboxFormat, parent::render($oElement));
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php
Original file line number Diff line number Diff line change
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) . "\n";
return sprintf(static::$formGroupFormat, $sRowClass, $sElementContent) . "\n";
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 '';
}
Expand Down
4 changes: 2 additions & 2 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TwbBundleFormStatic extends AbstractHelper
/**
* @var string
*/
private static $staticFormat = '<p class="form-control-static">%s</p>';
protected static $staticFormat = '<p class="form-control-static">%s</p>';

/**
* Invoke helper as functor
Expand All @@ -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());
}
}
12 changes: 6 additions & 6 deletions src/TwbBundle/View/Helper/TwbBundleAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class TwbBundleAlert extends AbstractHelper
/**
* @var string
*/
private static $alertFormat = '<div %s>%s</div>';
protected static $alertFormat = '<div %s>%s</div>';

/**
* @var string
*/
private static $dismissButtonFormat = '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>';
protected static $dismissButtonFormat = '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>';

/**
* Invoke helper as functor, proxies to {@link render()}.
Expand Down Expand Up @@ -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)) {
Expand All @@ -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
);
Expand Down
8 changes: 4 additions & 4 deletions src/TwbBundle/View/Helper/TwbBundleBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TwbBundleBadge extends AbstractHelper
/**
* @var string
*/
private static $badgeFormat = '<span %s>%s</span>';
protected static $badgeFormat = '<span %s>%s</span>';

/**
* Invoke helper as functor, proxies to {@link render()}.
Expand Down Expand Up @@ -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
);
Expand Down
4 changes: 2 additions & 2 deletions src/TwbBundle/View/Helper/TwbBundleButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit aac9657

Please sign in to comment.