Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Commit

Permalink
Update TwbBundleFormCheckbox.php
Browse files Browse the repository at this point in the history
Separate label content rendering
  • Loading branch information
neilime authored Jun 15, 2016
1 parent 149bdf2 commit e0044de
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<input %s%s', $this->createAttributesString($aAttributes), $sClosingBracket);

//Add label markup
// Add label markup
if ($this->getLabelPosition($oElement) === FormRow::LABEL_PREPEND) {
$sElementContent = $sLabelOpen .
($sLabelContent ? rtrim($sLabelContent) . ' ' : '') .
Expand All @@ -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
Expand Down

0 comments on commit e0044de

Please sign in to comment.