form = $form;
}
protected function renderDisplayGroups(QuickForm $form)
{
$html = '';
foreach ($form->getDisplayGroups() as $group) {
$elements = $this->filterGroupElements($group);
if (empty($elements)) {
continue;
}
$html .= '
' . $group->getLegend() . ' |
';
$html .= $this->renderElements($elements);
}
return $html;
}
/**
* @param ZfDisplayGroup $group
* @return ZfElement[]
*/
protected function filterGroupElements(ZfDisplayGroup $group)
{
$blacklist = array('disabled', 'assign_filter');
$elements = array();
/** @var ZfElement $element */
foreach ($group->getElements() as $element) {
if ($element->getValue() === null) {
continue;
}
if ($element->getType() === 'Zend_Form_Element_Hidden') {
continue;
}
if (in_array($element->getName(), $blacklist)) {
continue;
}
$elements[] = $element;
}
return $elements;
}
protected function renderElements($elements)
{
$html = '';
foreach ($elements as $element) {
$html .= $this->renderElement($element);
}
return $html;
}
/**
* @param ZfElement $element
*
* @return string
*/
protected function renderElement(ZfElement $element)
{
$value = $element->getValue();
return ''
. $this->escape($element->getLabel())
. ' | '
. $this->renderValue($value)
. ' |
';
}
protected function renderValue($value)
{
if (is_string($value)) {
return $this->escape($value);
} elseif (is_array($value)) {
return $this->escape(implode(', ', $value));
}
return $this->escape(PlainObjectRenderer::render($value));
}
protected function escape($string)
{
return htmlspecialchars($string);
}
public function render()
{
$this->form->initializeForObject();
return '' . "\n"
. $this->renderDisplayGroups($this->form)
. '
';
}
}