Created
February 5, 2014 13:32
-
-
Save neilime/8823655 to your computer and use it in GitHub Desktop.
Override TwbBundle\Form\View\Helper\TwbBundleFormElement
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 | |
namespace Test\Form\View\Helper; | |
class TestTwbBundleFormElement extends \TwbBundle\Form\View\Helper\TwbBundleFormElement | |
{ | |
/** | |
* Render an element | |
* @param \Zend\Form\ElementInterface $oElement | |
* @return string | |
*/ | |
public function render(\Zend\Form\ElementInterface $oElement) | |
{ | |
//Add form-controll class | |
$sElementType = $oElement->getAttribute('type'); | |
if (!in_array($sElementType, array('file', 'checkbox', 'radio', 'submit', 'multi_checkbox', 'static', 'button'))) { | |
if ($sElementClass = $oElement->getAttribute('class')) { | |
if (!preg_match('/(\s|^)form-control(\s|$)/', $sElementClass)) $oElement->setAttribute('class', trim($sElementClass . ' form-control')); | |
} else $oElement->setAttribute('class', 'form-control'); | |
} | |
switch(true){ | |
case '\TwbBundle\Form\Element\StaticElement': | |
$sMarkup = $this->getView()->formStatic()->render($oElement); | |
break; | |
case '\Test\Form\Element\MyElement': | |
$sMarkup = $this->getView()->myElement()->render($oElement); | |
break; | |
default : | |
$sMarkup = parent::render($oElement); | |
} | |
//Addon prepend | |
if ($aAddOnPrepend = $oElement->getOption('add-on-prepend')) $sMarkup = $this->renderAddOn($aAddOnPrepend) . $sMarkup; | |
//Addon append | |
if ($aAddOnAppend = $oElement->getOption('add-on-append')) $sMarkup .= $this->renderAddOn($aAddOnAppend); | |
if ($aAddOnAppend || $aAddOnPrepend) { | |
$sSpecialClass = ''; | |
//Input size | |
if ($sElementClass = $oElement->getAttribute('class')) { | |
if (preg_match('/(\s|^)input-lg(\s|$)/', $sElementClass)) $sSpecialClass .= ' input-group-lg'; | |
elseif (preg_match('/(\s|^)input-sm(\s|$)/', $sElementClass)) $sSpecialClass .= ' input-group-sm'; | |
} | |
return sprintf( | |
self::$inputGroupFormat, | |
trim($sSpecialClass), | |
$sMarkup | |
); | |
} | |
return $sMarkup; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment