/** * Method to get a form object. * * @param string $name The name of the form. * @param string $source The form source. Can be XML string if file flag is set to false. * @param array $options Optional array of options for the form creation. * @param boolean $clear Optional argument to force load a new form. * @param mixed $xpath An optional xpath to search for the fields. * * @return mixed JForm object on success, False on error. */ protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false) { static $form = null; // Handle the optional arguments. $options['control'] = JArrayHelper::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. RForm::addFormPath(JPATH_COMPONENT . '/models/forms'); RForm::addFieldPath(JPATH_COMPONENT . '/models/fields'); try { $form = RForm::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; }
/** * Add include paths for model class * * @param boolean $isAdmin Is client admin or site * @param string $optionName Option name * * @return void * * @since 1.3 */ public function addModelIncludePaths($isAdmin, $optionName) { if ($isAdmin) { $this->loadExtensionLanguage($optionName, JPATH_ADMINISTRATOR); $path = JPATH_ADMINISTRATOR . '/components/' . $optionName; RModel::addIncludePath($path . '/models'); JTable::addIncludePath($path . '/tables'); RForm::addFormPath($path . '/models/forms'); RForm::addFieldPath($path . '/models/fields'); } else { $this->loadExtensionLanguage($optionName); $path = JPATH_SITE . '/components/' . $optionName; RModel::addIncludePath($path . '/models'); JTable::addIncludePath($path . '/tables'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $optionName . '/tables'); RForm::addFormPath($path . '/models/forms'); RForm::addFieldPath($path . '/models/fields'); } if (!defined('JPATH_COMPONENT')) { define('JPATH_COMPONENT', $path); } }
/** * Loads form for Params field * * @param array $column Content element column * @param RTranslationContentElement $contentElement Content element * @param mixed $data The data expected for the form. * @param string $controlName Name of the form control group * * @return array Array or table with columns columns */ public static function loadParamsForm($column, $contentElement, $data, $controlName = '') { if (version_compare(JVERSION, '3.0', '<') && !empty($column['formname25'])) { $formName = !empty($column['formname']) ? $column['formname25'] : $column['name']; } else { $formName = !empty($column['formname']) ? $column['formname'] : $column['name']; } // Handle the optional arguments. $options = array(); $options['control'] = $controlName; $options['load_data'] = true; $formData = array(); if (!empty($data->{$column['name']})) { $registry = new JRegistry(); $registry->loadString($data->{$column['name']}); $formData[$column['name']] = $registry->toArray(); } // Load common and local language files. $lang = JFactory::getLanguage(); // Load language file $lang->load($contentElement->extension, JPATH_BASE, null, false, false) || $lang->load($contentElement->extension, JPATH_BASE . "/components/" . $contentElement->extension, null, false, false) || $lang->load($contentElement->extension, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($contentElement->extension, JPATH_BASE . "/components/" . $contentElement->extension, $lang->getDefault(), false, false); // Get the form. RForm::addFormPath(JPATH_BASE . '/components/' . $contentElement->extension . '/models/forms'); RForm::addFormPath(JPATH_BASE . '/administrator/components/' . $contentElement->extension . '/models/forms'); RForm::addFieldPath(JPATH_BASE . '/components/' . $contentElement->extension . '/models/fields'); RForm::addFieldPath(JPATH_BASE . '/administrator/components/' . $contentElement->extension . '/models/fields'); if (!empty($column['formpath'])) { RForm::addFormPath(JPATH_BASE . $column['formpath']); } if (!empty($column['fieldpath'])) { RForm::addFieldPath(JPATH_BASE . $column['fieldpath']); } $xpath = !empty($column['xpath']) ? $column['xpath'] : false; try { $form = RForm::getInstance('com_redcore.params_' . $column['name'] . $controlName, $formName, $options, false, $xpath); // Allow for additional modification of the form, and events to be triggered. // We pass the data because plugins may require it. self::preprocessForm($form, $data, 'content', $column, $contentElement); // Load the data into the form after the plugins have operated. $form->bind($formData); } catch (Exception $e) { return false; } if (empty($form)) { return false; } return $form; }