From e0044de153e2e5914e09374e986ff400a54d4b67 Mon Sep 17 00:00:00 2001 From: neilime Date: Wed, 15 Jun 2016 13:27:54 +0200 Subject: [PATCH] Update TwbBundleFormCheckbox.php Separate label content rendering --- .../View/Helper/TwbBundleFormCheckbox.php | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php index f60d2f4..43625da 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php @@ -55,24 +55,19 @@ public function render(ElementInterface $oElement) $aAttributes['checked'] = 'checked'; } - //Render label - $sLabelOpen = $sLabelClose = $sLabelContent = ''; - - //Render label and visible element - if ($sLabelContent = $oElement->getLabel()) { - if ($oTranslator = $this->getTranslator()) { - $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain()); - } - + // Render label + $sLabelOpen = $sLabelClose = ''; + $sLabelContent = $this->getLabelContent($oElement); + if($sLabelContent) { $oLabelHelper = $this->getLabelHelper(); $sLabelOpen = $oLabelHelper->openTag($oElement->getLabelAttributes() ? : null); $sLabelClose = $oLabelHelper->closeTag(); } - //Render checkbox + // Render checkbox $sElementContent = sprintf('createAttributesString($aAttributes), $sClosingBracket); - //Add label markup + // Add label markup if ($this->getLabelPosition($oElement) === FormRow::LABEL_PREPEND) { $sElementContent = $sLabelOpen . ($sLabelContent ? rtrim($sLabelContent) . ' ' : '') . @@ -98,6 +93,20 @@ public function render(ElementInterface $oElement) } return $sElementContent; } + + /** + * @param ElementInterface $oElement + * @return string + */ + public function getLabelContent(ElementInterface $oElement){ + $sLabelContent = $oElement->getLabel() ? : ''; + if ($sLabelContent) { + if ($oTranslator = $this->getTranslator()) { + $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain()); + } + } + return $sLabelContent; + } /** * Get the label position