public function widgetAction() { // Render by widget name $mod = $this->_getParam('mod'); $name = $this->_getParam('name'); if (null === $name) { throw new Exception('no widget found with name: ' . $name); } if (null !== $mod) { $name = $mod . '.' . $name; } $contentInfoRaw = $this->getContentAreas(); $contentInfo = array(); foreach ($contentInfoRaw as $info) { $contentInfo[$info['name']] = $info; } // It has a form specified in content manifest if (!empty($contentInfo[$name]['adminForm'])) { if (is_string($contentInfo[$name]['adminForm'])) { // Core_Form_Admin_Widget_* $formClass = $contentInfo[$name]['adminForm']; Engine_Loader::loadClass($formClass); $this->view->form = $form = new $formClass(); } else { if (is_array($contentInfo[$name]['adminForm'])) { $this->view->form = $form = new Engine_Form($contentInfo[$name]['adminForm']); } else { throw new Core_Model_Exception('Unable to load admin form class'); } } // Try to set title if missing if (!$form->getTitle()) { $form->setTitle('Editing: ' . $contentInfo[$name]['title']); } // Try to set description if missing if (!$form->getDescription()) { $form->setDescription('placeholder'); } $form->setAttrib('class', 'global_form_popup ' . $form->getAttrib('class')); // Add title element if (!$form->getElement('title')) { $form->addElement('Text', 'title', array('label' => 'Title', 'order' => -100)); } // Add mobile element? if (!$form->getElement('nomobile')) { $form->addElement('Select', 'nomobile', array('label' => 'Hide on mobile site?', 'order' => 100000 - 5, 'multiOptions' => array('1' => 'Yes, do not display on mobile site.', '0' => 'No, display on mobile site.'), 'value' => '0')); } if (!empty($contentInfo[$name]['isPaginated']) && !$form->getElement('itemCountPerPage')) { $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))), 'order' => 1000000 - 1)); } // Add submit button if (!$form->getElement('submit') && !$form->getElement('execute')) { $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000000)); } // Add name $form->addElement('Hidden', 'name', array('value' => $name, 'order' => 1000010)); if (!$form->getElement('cancel')) { $form->addElement('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000001)); } if (!$form->getDisplayGroup('buttons')) { $submitName = $form->getElement('execute') ? 'execute' : 'submit'; $form->addDisplayGroup(array($submitName, 'cancel'), 'buttons', array('order' => 1000002)); } // Force method and action $form->setMethod('post')->setAction($_SERVER['REQUEST_URI']); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $this->view->values = $form->getValues(); $this->view->form = null; } return; } // Try to render admin page if (!empty($contentInfo[$name])) { try { $structure = array('type' => 'widget', 'name' => $name, 'request' => $this->getRequest(), 'action' => 'admin', 'throwExceptions' => true); // Create element (with structure) $element = new Engine_Content_Element_Container(array('elements' => array($structure), 'decorators' => array('Children'))); $content = $element->render(); $this->getResponse()->setBody($content); $this->_helper->viewRenderer->setNoRender(true); return; } catch (Exception $e) { } } // Just render default editing form $this->view->form = $form = new Engine_Form(array('title' => $contentInfo[$name]['title'], 'description' => 'placeholder', 'method' => 'post', 'action' => $_SERVER['REQUEST_URI'], 'class' => 'global_form_popup', 'elements' => array(array('Text', 'title', array('label' => 'Title')), array('Button', 'submit', array('label' => 'Save', 'type' => 'submit', 'decorators' => array('ViewHelper'), 'ignore' => true, 'order' => 1501)), array('Hidden', 'name', array('value' => $name)), array('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1502))), 'displaygroups' => array('buttons' => array('name' => 'buttons', 'elements' => array('submit', 'cancel'), 'options' => array('order' => 1500))))); if (!empty($contentInfo[$name]['isPaginated'])) { $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))))); } if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $this->view->values = $form->getValues(); $this->view->form = null; } else { $form->populate($this->_getAllParams()); } }