/** * Apply this element to the form as the output decorator. * * @param \Zend_Form $form * @param mixed $width The style.width content for the labels * @param array $order The display order of the elements * @param string $errorClass Class name to display all errors in * @return \MUtil_Html_DlElement */ public function setAsFormLayout(\Zend_Form $form, $width = null, $order = array('label', 'element', 'description'), $errorClass = 'errors') { $this->_repeatTags = true; $prependErrors = $errorClass; // Make a Lazy repeater for the form elements and set it as the element repeater $formrep = new \MUtil_Lazy_RepeatableFormElements($form); $formrep->setSplitHidden(true); // These are treated separately $this->setRepeater($formrep); if (null === $width) { $attr = array(); } else { $attr['style'] = array('display' => 'inline-block', 'width' => $width); } // Place the choosen renderers foreach ($order as $renderer) { switch ($renderer) { case 'label': $this->label($formrep->element, $attr); // Set label with optional width break; case 'error': $prependErrors = false; // Intentional fall through // Intentional fall through default: $this->append($formrep->{$renderer}); } } // Set this element as the form decorator $decorator = new \MUtil_Html_ElementDecorator(); $decorator->setHtmlElement($this); $decorator->setPrologue($formrep); // Renders hidden elements before this element if ($prependErrors) { $decorator->setPrependErrors(\MUtil_Html_ListElement::ul(array('class' => $errorClass, 'style' => array('margin-left' => $width)))); } $form->setDecorators(array($decorator, 'AutoFocus', 'Form')); return $this; }
public function toUl($actionController = null) { if ($this->isVisible() && $this->hasChildren()) { $parameterSources = func_get_args(); $ul = \MUtil_Html_ListElement::ul(); foreach ($this->getChildren() as $menuItem) { if ($li = $menuItem->_toLi(new \Gems_Menu_ParameterCollector($parameterSources))) { $ul->append($li); } } if (count($ul)) { return $ul; } } }
/** * Output for viewing rols * * @param array $privileges * @return \MUtil_Html_ListElement */ public function formatPrivileges(array $privileges) { if (count($privileges)) { $output = \MUtil_Html_ListElement::ul(); $privileges = array_combine($privileges, $privileges); $output->class = 'allowed'; foreach ($this->getUsedPrivileges() as $privilege => $description) { if (isset($privileges[$privilege])) { $output->li()->raw($description); } } if (count($output)) { return $output; } } return \MUtil_Html::create('em', $this->_('No privileges found.')); }
/** * Helper function to load the menu items to the html element. * * Allows overloading by sub classes. * * @param \MUtil_Html_ListElement $ul * @param array $items * @param boolean $cascade render nested items */ protected function renderItems(\MUtil_Html_ListElement $ul, array $items, $cascade) { foreach ($items as $item) { if (isset($item['visible'], $item['label']) && $item['visible'] && $item['label']) { $url = $item['params']; $url['controller'] = $item['controller']; $url['action'] = $item['action']; $url['RouteReset'] = true; $li = $ul->li(); if (isset($item['active']) && $item['active']) { $li->class = 'active'; } if (isset($item['liClass']) && $item['liClass']) { $li->appendAttrib('class', $item['liClass']); } $a = $li->a($url, $item['label']); if (isset($item['class'])) { $a->class = $item['class']; } if (isset($item['target'])) { $a->target = $item['target']; } if ($cascade && isset($item['pages']) && is_array($item['pages'])) { $this->renderItems($li->ul(array('class' => 'subnav ' . $this->_menuUlClass)), $item['pages'], true); } } } }