/** * Create the setting form and populate with the custom setting values * * @param integer $groupid */ public static function createForm($groupid) { $form = new Zend_Form(array('action' => '/admin/settings/index/groupid/' . $groupid, 'method' => 'post')); $form->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $records = Doctrine_Query::create()->from('SettingsParameters s')->where('group_id = ?', $groupid)->execute(array(), Doctrine_Core::HYDRATE_ARRAY); if (!empty($records)) { foreach ($records as $record) { // Custom style added to the textareas $style = $record['type'] == "textarea" ? array('rows' => 4) : array(); $form->addElement($record['type'], $record['var'], $style + array('decorators' => array('Bootstrap'), 'filters' => array('StringTrim'), 'label' => $record['name'], 'description' => $record['description'], 'class' => 'form-control obj_' . $record['var'])); if (!empty($record['config'])) { $config = json_decode($record['config'], true); if (!empty($config['class']) && class_exists($config['class']) && !empty($config['method']) && method_exists($config['class'], $config['method'])) { $class = $config['class']; $method = $config['method']; $data = call_user_func(array($class, $method)); if (!empty($data)) { if ($record['type'] == "select") { $form->getElement($record['var'])->setMultiOptions($data); } else { $form->getElement($record['var'])->setValue($data); } } } } } } $settings = self::getValues(Settings::find_by_GroupId($groupid)); $form->populate($settings); return $form; }
/** * Set Form defaults * - disable default decorators * - set form & displaygroup decorators * - set needed prefix path for bootstrap decorators * - set form element decorators * * @param Zend_Form $form The form instance. * @param string $format Standard, minimal, table. * * @return void */ protected static function setFormDefaults(Zend_Form $form, $format) { $form->setDisableLoadDefaultDecorators(true); $form->setDisplayGroupDecorators(self::$_DisplayGroupDecorator[$format]); $form->setDecorators(self::$_FormDecorator[$format]); if (self::BOOTSTRAP == $format || self::BOOTSTRAP_MINIMAL == $format) { $form->addElementPrefixPath('Dfi_Form_Decorator', 'Dfi/Form/Decorator', Zend_Form::DECORATOR); $form->addPrefixPath('Dfi_Form_Decorator', 'Dfi/Form/Decorator', Zend_Form::DECORATOR); } $form->setElementDecorators(self::$_ElementDecorator[$format]); return; }
public function testCanSetElementDecoratorPrefixPath() { $this->setupElements(); $this->form->addElementPrefixPath('Zend_Foo', 'Zend/Foo/', 'decorator'); $this->form->addElement('text', 'prefixTest'); foreach ($this->form->getElements() as $element) { $loader = $element->getPluginLoader('decorator'); $paths = $loader->getPaths('Zend_Foo'); $this->assertFalse(empty($paths)); $this->assertContains('Foo', $paths[0]); $this->assertNotContains('Decorator', $paths[0]); } }
/** * initForm * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected function initForm() { $this->objForm = new Zend_Form(); /** * Use our own PluginLoader */ $objLoader = new PluginLoader(); $objLoader->setPluginLoader($this->objForm->getPluginLoader(PluginLoader::TYPE_FORM_ELEMENT)); $objLoader->setPluginType(PluginLoader::TYPE_FORM_ELEMENT); $this->objForm->setPluginLoader($objLoader, PluginLoader::TYPE_FORM_ELEMENT); /** * clear all decorators */ $this->objForm->clearDecorators(); /** * add standard decorators */ $this->objForm->addDecorator('TabContainer'); $this->objForm->addDecorator('FormElements'); $this->objForm->addDecorator('Form'); /** * add form prefix path */ $this->objForm->addPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * elements prefixes */ $this->objForm->addElementPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * regions prefixes */ $this->objForm->addDisplayGroupPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/'); $this->objForm->setAttrib('id', 'genForm'); $this->objForm->setAttrib('onsubmit', 'return false;'); $this->objForm->addElement('hidden', 'id', array('decorators' => array('Hidden'))); $this->objForm->addElement('text', 'title', array('label' => $this->core->translate->_('title', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text keyfield', 'required' => true)); $this->objForm->addElement('text', 'key', array('label' => $this->core->translate->_('key', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text', 'required' => true)); $this->objForm->addDisplayGroup(array('title', 'key'), 'main-resource'); $this->objForm->getDisplayGroup('main-resource')->setLegend($this->core->translate->_('General_information', false)); $this->objForm->getDisplayGroup('main-resource')->setDecorators(array('FormElements', 'Region')); $arrGroups = array(); $sqlStmt = $this->core->dbh->query("SELECT `id`, `title` FROM `groups` ORDER BY `title`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrGroups[$arrSql['id']] = $arrSql['title']; } $this->objForm->addElement('multiCheckbox', 'groups', array('label' => $this->core->translate->_('groups', false), 'value' => $this->arrGroups, 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrGroups)); $this->objForm->addDisplayGroup(array('groups'), 'groups-group'); $this->objForm->getDisplayGroup('groups-group')->setLegend($this->core->translate->_('Resource_groups', false)); $this->objForm->getDisplayGroup('groups-group')->setDecorators(array('FormElements', 'Region')); }
/** * Add a form group/subform * * @param Zend_Form $form * @param string $name * @param int $order * @return Zend_Form */ public function addSubForm(Zend_Form $form, $name, $order = null) { $name = (string) $name; foreach ($this->_loaders as $type => $loader) { $loaderPaths = $loader->getPaths(); foreach ($loaderPaths as $prefix => $paths) { foreach ($paths as $path) { $form->addPrefixPath($prefix, $path, $type); } } } if (!empty($this->_elementPrefixPaths)) { foreach ($this->_elementPrefixPaths as $spec) { list($prefix, $path, $type) = array_values($spec); $form->addElementPrefixPath($prefix, $path, $type); } } if (!empty($this->_displayGroupPrefixPaths)) { foreach ($this->_displayGroupPrefixPaths as $spec) { list($prefix, $path) = array_values($spec); $form->addDisplayGroupPrefixPath($prefix, $path); } } if (null !== $order) { $form->setOrder($order); } if (($oldName = $form->getName()) && $oldName !== $name && $oldName === $form->getElementsBelongTo()) { $form->setElementsBelongTo($name); } $form->setName($name); $form->setParent($name, $this->getParent()); $this->_subForms[$name] = $form; $this->_order[$name] = $order; $this->_orderUpdated = true; return $this; }
/** * Add a form group/subform * * @param Zend_Form $form * @param string $name * @param int $order * @return Zend_Form */ public function addSubForm(Zend_Form $form, $name, $order = null) { $name = (string) $name; foreach ($this->_loaders as $type => $loader) { $loaderPaths = $loader->getPaths(); foreach ($loaderPaths as $prefix => $paths) { foreach ($paths as $path) { $form->addPrefixPath($prefix, $path, $type); } } } if (!empty($this->_elementPrefixPaths)) { foreach ($this->_elementPrefixPaths as $spec) { list($prefix, $path, $type) = $spec; $form->addElementPrefixPath($prefix, $path, $spec); } } if (!empty($this->_displayGroupPrefixPaths)) { foreach ($this->_displayGroupPrefixPaths as $spec) { list($prefix, $path) = $spec; $form->addDisplayGroupPrefixPath($prefix, $path); } } $this->_subForms[$name] = $form; $this->_order[$name] = $order; $this->_orderUpdated = true; return $this; }
/** * @group ZF-9682 */ public function testCustomLabelDecorator() { $form = new Zend_Form(); $form->addElementPrefixPath('My_Decorator', dirname(__FILE__) . '/../_files/decorators/', 'decorator'); $form->addElement($this->element); $element = $form->getElement('foo'); $this->assertType('My_Decorator_Label', $element->getDecorator('Label')); }
/** * Set the form decorators by the given string format or by the default div style * * @param object $objForm Zend_Form pointer-reference * @param string $constFormat Project_Plugin_FormDecoratorDefinition constants * @return NULL */ public static function setFormDecorator(Zend_Form $form, $format = self::BOOTSTRAP, $submit_str = 'submit', $cancel_str = 'cancel') { /** * - disable default decorators * - set form & displaygroup decorators */ $form->setDisableLoadDefaultDecorators(true); $form->setDisplayGroupDecorators(self::$_DisplayGroupDecorator[$format]); $form->setDecorators(self::$_FormDecorator[$format]); // set needed prefix path for bootstrap decorators if ($format == self::BOOTSTRAP) { $form->addElementPrefixPath('EasyBib_Form_Decorator', 'EasyBib/Form/Decorator', Zend_Form::DECORATOR); } // set form element decorators $form->setElementDecorators(self::$_ElementDecorator[$format]); // set submit button decorators if ($form->getElement($submit_str)) { $form->getElement($submit_str)->setDecorators(self::$_SubmitDecorator[$format]); if ($format == self::BOOTSTRAP) { $attribs = $form->getElement($submit_str)->getAttrib('class'); if (empty($attribs)) { $attribs = array('btn', 'primary'); } else { if (is_string($attribs)) { $attribs = array($attribs); } $attribs = array_unique(array_merge(array('btn'), $attribs)); } $form->getElement($submit_str)->setAttrib('class', $attribs)->setAttrib('type', 'submit'); if ($form->getElement($cancel_str)) { $form->getElement($submit_str)->getDecorator('HtmlTag')->setOption('openOnly', true); } } } // set cancel button decorators if ($form->getElement($cancel_str)) { $form->getElement($cancel_str)->setDecorators(self::$_ResetDecorator[$format]); if ($format == self::BOOTSTRAP) { $attribs = $form->getElement($cancel_str)->getAttrib('class'); if (empty($attribs)) { $attribs = array('btn'); } else { if (is_string($attribs)) { $attribs = array($attribs); } $attribs = array_unique(array_merge(array('btn'), $attribs)); } $form->getElement($cancel_str)->setAttrib('class', $attribs)->setAttrib('type', 'reset'); if ($form->getElement($submit_str)) { $form->getElement($cancel_str)->getDecorator('HtmlTag')->setOption('closeOnly', true); } } } // set hidden input decorators foreach ($form->getElements() as $e) { if ($e->getType() == 'Zend_Form_Element_Hidden') { $e->setDecorators(self::$_HiddenDecorator[$format]); } } }
public static function init(Zend_Form $form) { $form->addPrefixPath('Zmz_Form_', 'ZMZ/Form/'); $form->addPrefixPath('Zmz_Filter_', 'ZMZ/Filter/'); $form->addElementPrefixPath('Zmz_Form_Decorators_Filter_', 'ZMZ/Form/Decorators/Filter/', 'decorator'); }
/** * initForm * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ protected function initForm() { $this->objForm = new Zend_Form(); /** * Use our own PluginLoader */ $objLoader = new PluginLoader(); $objLoader->setPluginLoader($this->objForm->getPluginLoader(PluginLoader::TYPE_FORM_ELEMENT)); $objLoader->setPluginType(PluginLoader::TYPE_FORM_ELEMENT); $this->objForm->setPluginLoader($objLoader, PluginLoader::TYPE_FORM_ELEMENT); /** * clear all decorators */ $this->objForm->clearDecorators(); /** * add standard decorators */ $this->objForm->addDecorator('TabContainer'); $this->objForm->addDecorator('FormElements'); $this->objForm->addDecorator('Form'); /** * add form prefix path */ $this->objForm->addPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * elements prefixes */ $this->objForm->addElementPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/', 'decorator'); /** * regions prefixes */ $this->objForm->addDisplayGroupPrefixPath('Form_Decorator', GLOBAL_ROOT_PATH . 'library/massiveart/generic/forms/decorators/'); $arrGroupTypeOptions = array(); $sqlStmt = $this->core->dbh->query("SELECT `id`, `title` FROM `groupTypes`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrGroupTypeOptions[$arrSql['id']] = ucfirst($arrSql['title']); } $this->objForm->setAttrib('id', 'genForm'); $this->objForm->setAttrib('onsubmit', 'return false;'); $this->objForm->addElement('hidden', 'id', array('decorators' => array('Hidden'))); $this->objForm->addElement('text', 'title', array('label' => $this->core->translate->_('title', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text keyfield', 'required' => true)); $this->objForm->addElement('text', 'key', array('label' => $this->core->translate->_('key', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text', 'required' => true)); $this->objForm->addElement('textarea', 'description', array('label' => $this->core->translate->_('description', false), 'decorators' => array('Input'), 'columns' => 12, 'class' => 'text')); $this->objForm->addElement('multiCheckbox', 'groupTypes', array('label' => $this->core->translate->_('groupTypes', false), 'value' => $this->arrGroupTypes, 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrGroupTypeOptions)); $this->objForm->addDisplayGroup(array('title', 'key', 'description', 'groupTypes'), 'main-group', array('columns' => 9)); $this->objForm->getDisplayGroup('main-group')->setLegend($this->core->translate->_('General_information', false)); $this->objForm->getDisplayGroup('main-group')->setDecorators(array('FormElements', 'Region')); $arrPermissionOptions = array(); $sqlStmt = $this->core->dbh->query("SELECT `id`, UCASE(`title`) AS title FROM `permissions`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrPermissionOptions[$arrSql['id']] = $arrSql['title']; } $arrLanguageOptions = array(); $arrLanguageOptions['0'] = $this->core->translate->_('All_languages', false); $sqlStmt = $this->core->dbh->query("SELECT `id`, `title` FROM `languages`")->fetchAll(); foreach ($sqlStmt as $arrSql) { $arrLanguageOptions[$arrSql['id']] = $arrSql['title']; } $strRegionInstances = ''; $intRegionCounter = 0; /** * create group permisson regions */ foreach ($this->arrPermissions as $arrPermission) { $intRegionCounter++; $this->objForm->addElement('radio', 'language_' . $intRegionCounter, array('label' => $this->core->translate->_('language', false), 'value' => $arrPermission['language'], 'decorators' => array('Input'), 'columns' => 6, 'class' => 'radio', 'MultiOptions' => $arrLanguageOptions)); $this->objForm->addElement('multiCheckbox', 'permissions_' . $intRegionCounter, array('label' => $this->core->translate->_('permissions', false), 'value' => $arrPermission['permissions'], 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrPermissionOptions)); $this->objForm->addDisplayGroup(array('language_' . $intRegionCounter, 'permissions_' . $intRegionCounter), 'Permission_' . $intRegionCounter, array('columns' => 9, 'regionTypeId' => 1, 'collapsable' => 0, 'regionCounter' => $intRegionCounter, 'regionId' => 'Permission', 'regionExt' => $intRegionCounter, 'isMultiply' => true, 'regionTitle' => $this->core->translate->_('Language_specific', false))); $this->objForm->getDisplayGroup('Permission_' . $intRegionCounter)->setLegend($this->core->translate->_('Permissions', false)); $this->objForm->getDisplayGroup('Permission_' . $intRegionCounter)->setDecorators(array('FormElements', 'Region')); $strRegionInstances .= '[' . $intRegionCounter . ']'; } $this->objForm->addElement('radio', 'language_REPLACE_n', array('label' => $this->core->translate->_('language', false), 'decorators' => array('Input'), 'columns' => 6, 'class' => 'radio', 'MultiOptions' => $arrLanguageOptions)); $this->objForm->addElement('multiCheckbox', 'permissions_REPLACE_n', array('label' => $this->core->translate->_('permissions', false), 'decorators' => array('Input'), 'columns' => 6, 'class' => 'multiCheckbox', 'MultiOptions' => $arrPermissionOptions)); $this->objForm->addDisplayGroup(array('language_REPLACE_n', 'permissions_REPLACE_n'), 'Permission_REPLACE_n', array('columns' => 9, 'regionTypeId' => 1, 'collapsable' => 0, 'regionId' => 'Permission', 'regionExt' => 'REPLACE_n', 'isMultiply' => true, 'isEmptyWidget' => true, 'regionTitle' => $this->core->translate->_('Language_specific', false))); $this->objForm->getDisplayGroup('Permission_REPLACE_n')->setLegend('Rechte'); $this->objForm->getDisplayGroup('Permission_REPLACE_n')->setDecorators(array('FormElements', 'Region')); $this->objForm->addElement('hidden', 'Region_Permission_Instances', array('value' => $strRegionInstances, 'decorators' => array('Hidden'))); $this->objForm->addElement('hidden', 'Region_Permission_Order', array('value' => '', 'decorators' => array('Hidden'))); }