protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false) { // Handle the optional arguments. $options['control'] = MArrayHelper::getValue($options, 'control', false); // Create a signature hash. $hash = md5($source . serialize($options)); // Check if we can use a previously loaded form. if (isset($this->_forms[$hash]) && !$clear) { return $this->_forms[$hash]; } // Get the form. MForm::addFormPath(MPATH_COMPONENT . '/models/forms'); MForm::addFieldPath(MPATH_COMPONENT . '/models/fields'); try { $form = MForm::getInstance($name, $source, $options, false, $xpath); if (isset($options['load_data']) && $options['load_data']) { // Get the data for the form. $data = $this->loadFormData(); } else { $data = array(); } // Allow for additional modification of the form, and events to be triggered. // We pass the data because plugins may require it. $this->preprocessForm($form, $data); // Load the data into the form after the plugins have operated. $form->bind($data); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } // Store the form for later. $this->_forms[$hash] = $form; return $form; }
protected static function _load() { if (self::$plugins !== null) { return self::$plugins; } mimport('framework.filesystem.folder'); if (!MFolder::exists(MPATH_PLUGINS)) { self::$plugins = array(); return self::$plugins; } $folders = MFolder::folders(MPATH_PLUGINS); if (empty($folders)) { self::$plugins = array(); return self::$plugins; } self::$plugins = array(); foreach ($folders as $folder) { $folder = str_replace('plg_', '', $folder); list($type, $name) = explode('_', $folder); $plg = new stdClass(); $plg->type = $type; $plg->name = $name; $plg->params = null; $xml_file = MPATH_MIWI . '/plugins/plg_' . $type . '_' . $name . '/' . $name . '.xml'; if (file_exists($xml_file)) { $form = MForm::getInstance($folder . '_form', $xml_file, array(), false, 'config'); $field_sets = $form->getFieldsets(); if (!empty($field_sets)) { $params = array(); foreach ($field_sets as $name => $field_set) { foreach ($form->getFieldset($name) as $field) { $field_name = $field->get('fieldname'); $field_value = $field->get('value'); $params[$field_name] = $field_value; } } $plg->params = json_encode($params); } } self::$plugins[] = $plg; } return self::$plugins; }