Created
February 18, 2013 13:42
-
-
Save neilime/4977484 to your computer and use it in GitHub Desktop.
Exemple overriding FormRow Helper for adding "required" class to element's label if it has required attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This class ovveride FormRow view helper | |
* The file should be in "module/Application/src/Application/Form/View/Helper" directory | |
*/ | |
namespace Application\Form\View\Helper; | |
class ExempleFormRow extends \TwbBundle\Form\View\Helper\TwbBundleFormRow{ | |
public function render(\Zend\Form\ElementInterface $oElement){ | |
if($oElement->getAttribute('required') === true){ | |
$aLabelAttributes = $oElement->getLabelAttributes()?:$this->labelAttributes; | |
if(empty($aLabelAttributes['class']))$aLabelAttributes['class'] = 'required'; | |
elseif(strpos($aLabelAttributes['class'], 'required') === false)$aLabelAttributes['class'] .= ' required'; | |
$oElement->setLabelAttributes($aLabelAttributes); | |
} | |
return parent::render($oElement); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Config for Application module | |
return array( | |
//... | |
'view_helpers' => array( | |
'invokables' => array( | |
//Define formRow service | |
'formRow' => 'Application\Form\View\Helper\ExempleFormRow', | |
) | |
) | |
//... | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment