This repository has been archived by the owner on Jul 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
neilime
committed
Mar 16, 2014
1 parent
88dce5b
commit 19460e2
Showing
59 changed files
with
2,483 additions
and
2,021 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
89 changes: 44 additions & 45 deletions
89
src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,92 @@ | ||
<?php | ||
|
||
namespace TwbBundle\Form\View\Helper; | ||
class TwbBundleFormCollection extends \Zend\Form\View\Helper\FormCollection{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $legendFormat = '<legend %s>%s</legend>'; | ||
class TwbBundleFormCollection extends \Zend\Form\View\Helper\FormCollection { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $fieldsetFormat = '<fieldset %s>%s</fieldset>'; | ||
/** | ||
* @var string | ||
*/ | ||
private static $legendFormat = '<legend%s>%s</legend>'; | ||
|
||
/** | ||
* Attributes valid for the tag represented by this helper | ||
* @var array | ||
*/ | ||
protected $validTagAttributes = array( | ||
'disabled' => true | ||
); | ||
/** | ||
* @var string | ||
*/ | ||
private static $fieldsetFormat = '<fieldset%s>%s</fieldset>'; | ||
|
||
/** | ||
* Render a collection by iterating through all fieldsets and elements | ||
* @param \Zend\Form\ElementInterface $oElement | ||
* @return string | ||
*/ | ||
public function render(\Zend\Form\ElementInterface $oElement){ | ||
/** | ||
* Attributes valid for the tag represented by this helper | ||
* @var array | ||
*/ | ||
protected $validTagAttributes = array( | ||
'disabled' => true | ||
); | ||
|
||
$oRenderer = $this->getView(); | ||
if(!method_exists($oRenderer, 'plugin'))return ''; | ||
/** | ||
* Render a collection by iterating through all fieldsets and elements | ||
* @param \Zend\Form\ElementInterface $oElement | ||
* @return string | ||
*/ | ||
public function render(\Zend\Form\ElementInterface $oElement) { | ||
$oRenderer = $this->getView(); | ||
if (!method_exists($oRenderer, 'plugin')) { | ||
return ''; | ||
} | ||
|
||
$bShouldWrap = $this->shouldWrap; | ||
|
||
$sMarkup = ''; | ||
$sMarkup = ''; | ||
$sElementLayout = $oElement->getOption('twb-layout'); | ||
if($oElement instanceof \IteratorAggregate){ | ||
$oElementHelper = $this->getElementHelper(); | ||
$oFieldsetHelper = $this->getFieldsetHelper(); | ||
if ($oElement instanceof \IteratorAggregate) { | ||
$oElementHelper = $this->getElementHelper(); | ||
$oFieldsetHelper = $this->getFieldsetHelper(); | ||
|
||
foreach($oElement->getIterator() as $oElementOrFieldset){ | ||
foreach ($oElement->getIterator() as $oElementOrFieldset) { | ||
$aOptions = $oElementOrFieldset->getOptions(); | ||
if ($sElementLayout && empty($aOptions['twb-layout'])) { | ||
$aOptions['twb-layout'] = $sElementLayout; | ||
$oElementOrFieldset->setOptions($aOptions); | ||
} | ||
|
||
if ($oElementOrFieldset instanceof \Zend\Form\FieldsetInterface) { | ||
if ($oElementOrFieldset instanceof \Zend\Form\FieldsetInterface) { | ||
$sMarkup .= $oFieldsetHelper($oElementOrFieldset); | ||
} elseif ($oElementOrFieldset instanceof \Zend\Form\ElementInterface) { | ||
$sMarkup .= $oElementHelper($oElementOrFieldset); | ||
} | ||
} | ||
if ($oElement instanceof \Zend\Form\Element\Collection && $oElement->shouldCreateTemplate()) { | ||
if ($oElement instanceof \Zend\Form\Element\Collection && $oElement->shouldCreateTemplate()) { | ||
$sMarkup .= $this->renderTemplate($oElement); | ||
} | ||
} | ||
|
||
if($bShouldWrap) { | ||
if(($sLabel = $oElement->getLabel())){ | ||
if ($bShouldWrap) { | ||
if (($sLabel = $oElement->getLabel())) { | ||
if (null !== ($oTranslator = $this->getTranslator())) { | ||
$sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); | ||
} | ||
|
||
$sMarkup = sprintf( | ||
self::$legendFormat, | ||
$this->createAttributesString($oElement->getLabelAttributes()?:array()), | ||
$this->getEscapeHtmlHelper()->__invoke($sLabel) | ||
).$sMarkup; | ||
self::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel) | ||
) . $sMarkup; | ||
} | ||
|
||
//Set form layout class | ||
if($sElementLayout){ | ||
$sLayoutClass = 'form-'.$sElementLayout; | ||
if ($sElementLayout) { | ||
$sLayoutClass = 'form-' . $sElementLayout; | ||
if ($sElementClass = $oElement->getAttribute('class')) { | ||
if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sElementClass)) { | ||
$oElement->setAttribute('class', trim($sElementClass . ' ' . $sLayoutClass)); | ||
} | ||
} | ||
else { | ||
} else { | ||
$oElement->setAttribute('class', $sLayoutClass); | ||
} | ||
} | ||
|
||
$sMarkup = sprintf( | ||
self::$fieldsetFormat, | ||
$this->createAttributesString($oElement->getAttributes()), | ||
$sMarkup | ||
self::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup | ||
); | ||
} | ||
return $sMarkup; | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.