本文整理汇总了PHP中JModelAdmin::preprocessForm方法的典型用法代码示例。如果您正苦于以下问题:PHP JModelAdmin::preprocessForm方法的具体用法?PHP JModelAdmin::preprocessForm怎么用?PHP JModelAdmin::preprocessForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JModelAdmin
的用法示例。
在下文中一共展示了JModelAdmin::preprocessForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preprocessForm
/**
* Auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
* @since 3.0
*/
protected function preprocessForm(JForm $form, $data, $group = 'jevents')
{
// Association content items
$app = JFactory::getApplication();
$assoc = false && JLanguageAssociations::isEnabled() && JFactory::getApplication()->isAdmin();
if ($assoc) {
$languages = JLanguageHelper::getLanguages('lang_code');
$addform = new SimpleXMLElement('<form />');
$fields = $addform->addChild('fields');
$fields->addAttribute('name', 'associations');
$fieldset = $fields->addChild('fieldset');
$fieldset->addAttribute('name', 'item_associations');
$fieldset->addAttribute('description', 'COM_JEVENTS_ITEM_ASSOCIATIONS_FIELDSET_DESC');
$add = false;
foreach ($languages as $tag => $language) {
if (empty($data->language) || $tag != $data->language) {
$add = true;
$field = $fieldset->addChild('field');
$field->addAttribute('name', $tag);
$field->addAttribute('type', 'modal_article');
$field->addAttribute('language', $tag);
$field->addAttribute('label', $language->title);
$field->addAttribute('translate_label', 'false');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
}
}
if ($add) {
$form->load($addform, false);
}
}
parent::preprocessForm($form, $data, $group);
}
示例2: preprocessForm
protected function preprocessForm(JForm $form, $data, $groups = '')
{
$obj = is_array($data) ? JArrayHelper::toObject($data, 'JObject') : $data;
if (isset($obj->alias) && $obj->id > 0) {
$form->setFieldAttribute('type', 'readonly', 'true');
}
parent::preprocessForm($form, $data);
}
示例3: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$parts = explode('.', JFactory::getApplication()->input->getCmd('context', $this->getState('field.context')));
$component = $parts[0];
if (isset($data->type)) {
$this->loadTypeForms($form, $data->type, $component);
$form->setFieldAttribute('type', 'component', $component);
// Setting the context for the category field
$cat = JCategories::getInstance(str_replace('com_', '', $component));
if ($cat && $cat->get('root')->hasChildren()) {
$form->setFieldAttribute('catid', 'extension', $component);
} else {
$form->removeField('catid');
}
// Not alowed to change the type of an existing record
if ($data->id) {
$form->setFieldAttribute('type', 'readonly', 'true');
}
}
$form->setFieldAttribute('type', 'component', $component);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例4: preprocessForm
/**
* Method to preprocess the form
*
* @param JForm $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 1.6
* @throws Exception if there is an error loading the form.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
jimport('joomla.filesystem.path');
$lang = JFactory::getLanguage();
$clientId = $this->getState('item.client_id');
$module = $this->getState('item.module');
$client = JApplicationHelper::getClientInfo($clientId);
$formFile = JPath::clean($client->path . '/modules/' . $module . '/' . $module . '.xml');
// Load the core and/or local language file(s).
$lang->load($module, $client->path, null, false, true) || $lang->load($module, $client->path . '/modules/' . $module, null, false, true);
if (file_exists($formFile)) {
// Get the module form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/extension/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
}
}
// Load the default advanced params
JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_modules/models/forms');
$form->loadFile('advanced', false);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例5: preprocessForm
/**
* Method to preprocess the form.
*
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $groups The name of the plugin group to import.
*
* @return void
*
* @see JFormField
* @since 1.6
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
jimport('joomla.filesystem.path');
// Initialise variables.
$lang = JFactory::getLanguage();
$extension = $this->getState('category.extension');
$component = $this->getState('category.component');
$section = $this->getState('category.section');
// Get the component form if it exists
jimport('joomla.filesystem.path');
$name = 'category' . ($section ? '.' . $section : '');
// Looking first in the component models/forms folder
$path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/models/forms/{$name}.xml");
// Old way: looking in the component folder
if (!file_exists($path)) {
$path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/{$name}.xml");
}
if (file_exists($path)) {
$lang->load($component, JPATH_BASE, null, false, false);
$lang->load($component, JPATH_BASE, $lang->getDefault(), false, false);
if (!$form->loadFile($path, false)) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
// Try to find the component helper.
$eName = str_replace('com_', '', $component);
$path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/helpers/category.php");
if (file_exists($path)) {
require_once $path;
$cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) {
$lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
// Check for an error.
if ($form instanceof Exception) {
$this->setError($form->getMessage());
return false;
}
}
}
// Set the access control rules field component value.
$form->setFieldAttribute('rules', 'component', $component);
$form->setFieldAttribute('rules', 'section', $name);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例6: preprocessForm
/**
* @param object $form A form object.
* @param mixed $data The data expected for the form.
*
* @return void
* @since 1.6
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
// Initialise variables.
$link = $this->getState('item.link');
$type = $this->getState('item.type');
$formFile = false;
// Initialise form with component view params if available.
if ($type == 'component') {
$link = htmlspecialchars_decode($link);
// Parse the link arguments.
$args = array();
parse_str(parse_url(htmlspecialchars_decode($link), PHP_URL_QUERY), $args);
// Confirm that the option is defined.
$option = '';
$base = '';
if (isset($args['option'])) {
// The option determines the base path to work with.
$option = $args['option'];
$base = JPATH_SITE . '/components/' . $option;
}
// Confirm a view is defined.
$formFile = false;
if (isset($args['view'])) {
$view = $args['view'];
// Determine the layout to search for.
if (isset($args['layout'])) {
$layout = $args['layout'];
} else {
$layout = 'default';
}
$formFile = false;
// Check for the layout XML file. Use standard xml file if it exists.
$path = JPath::clean($base . '/views/' . $view . '/tmpl/' . $layout . '.xml');
if (JFile::exists($path)) {
$formFile = $path;
}
// if custom layout, get the xml file from the template folder
// template folder is first part of file name -- template:folder
if (!$formFile && strpos($layout, ':') > 0) {
$temp = explode(':', $layout);
$templatePath = JPATH::clean(JPATH_SITE . '/templates/' . $temp[0] . '/html/' . $option . '/' . $view . '/' . $temp[1] . '.xml');
if (JFile::exists($templatePath)) {
$formFile = $templatePath;
}
}
}
//Now check for a view manifest file
if (!$formFile) {
$path = JPath::clean($base . '/views/metadata.xml');
if (JFile::exists($path)) {
$formFile = $path;
} else {
//Now check for a component manifest file
$path = JPath::clean($base . '/metadata.xml');
if (JFile::exists($path)) {
$formFile = $path;
}
}
}
}
if ($formFile) {
// If an XML file was found in the component, load it first.
// We need to qualify the full path to avoid collisions with component file names.
if ($form->loadFile($formFile, true, '/metadata') == false) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/metadata/layout/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$helpLoc = trim((string) $help[0]['local']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
$this->helpLocal = $helpLoc == 'true' || $helpLoc == '1' || $helpLoc == 'local' ? true : false;
}
}
// Now load the component params.
// TODO: Work out why 'fixing' this breaks JForm
if ($isNew = false) {
$path = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $option . '/config.xml');
} else {
$path = 'null';
}
if (JFile::exists($path)) {
// Add the component params last of all to the existing form.
//.........这里部分代码省略.........
示例7: preprocessForm
/**
* Method to allow derived classes to preprocess the form.
*
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 1.6
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$clientId = $this->getState('item.client_id');
$template = $this->getState('item.template');
$lang = JFactory::getLanguage();
$client = JApplicationHelper::getClientInfo($clientId);
if (!$form->loadFile('style_' . $client->name, true)) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
jimport('joomla.filesystem.path');
$formFile = JPath::clean($client->path . '/templates/' . $template . '/templateDetails.xml');
// Load the core and/or local language file(s).
$lang->load('tpl_' . $template, $client->path, null, false, true) || $lang->load('tpl_' . $template, $client->path . '/templates/' . $template, null, false, true);
if (file_exists($formFile)) {
// Get the template form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
// Disable home field if it is default style
if (is_array($data) && array_key_exists('home', $data) && $data['home'] == '1' || is_object($data) && isset($data->home) && $data->home == '1') {
$form->setFieldAttribute('home', 'readonly', 'true');
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/extension/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例8: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'plugin')
{
// Figure out the provider/channel selected.. either from the request or from the saved table data
if (empty($data)) {
$jform = JFactory::getApplication()->input->post->get('jform', array(), 'array');
$provider = isset($jform['provider']) ? $jform['provider'] : null;
$type = isset($jform['type']) ? $jform['type'] : null;
} else {
$provider = isset($data->provider) ? $data->provider : null;
$type = isset($data->type) ? $data->type : null;
}
if ($provider && $type) {
JForm::addFieldPath(JPATH_SITE . '/components/com_jfbconnect/libraries/provider/' . $provider . '/channel/fields');
$formFile = JPATH_SITE . '/components/com_jfbconnect/libraries/provider/' . $provider . '/channel/' . $type . '_outbound.xml';
if (file_exists($formFile)) {
if (!$form->loadFile($formFile, false)) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例9: preprocessForm
/**
* @param object $form A form object.
* @param mixed $data The data expected for the form.
*
* @return void
* @since 1.6
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
// Initialise variables.
$link = $this->getState('item.link');
$type = $this->getState('item.type');
$formFile = false;
// Initialise form with component view params if available.
if ($type == 'component') {
$link = htmlspecialchars_decode($link);
// Parse the link arguments.
$args = array();
parse_str(parse_url(htmlspecialchars_decode($link), PHP_URL_QUERY), $args);
// Confirm that the option is defined.
$option = '';
$base = '';
if (isset($args['option'])) {
// The option determines the base path to work with.
$option = $args['option'];
$base = JPATH_SITE . '/components/' . $option;
}
// Confirm a view is defined.
$formFile = false;
if (isset($args['view'])) {
$view = $args['view'];
// Determine the layout to search for.
if (isset($args['layout'])) {
$layout = $args['layout'];
} else {
$layout = 'default';
}
$formFile = false;
// Check for the layout XML file. Use standard xml file if it exists.
$path = JPath::clean($base . '/views/' . $view . '/tmpl/' . $layout . '.xml');
if (JFile::exists($path)) {
$formFile = $path;
}
// if custom layout, get the xml file from the template folder
// template folder is first part of file name -- template:folder
if (!$formFile && strpos($layout, ':') > 0) {
$temp = explode(':', $layout);
$templatePath = JPATH::clean(JPATH_SITE . '/templates/' . $temp[0] . '/html/' . $option . '/' . $view . '/' . $temp[1] . '.xml');
if (JFile::exists($templatePath)) {
$formFile = $templatePath;
}
}
}
//Now check for a view manifest file
if (!$formFile) {
if (isset($view) && JFile::exists($path = JPath::clean($base . '/views/' . $view . '/metadata.xml'))) {
$formFile = $path;
} else {
//Now check for a component manifest file
$path = JPath::clean($base . '/metadata.xml');
if (JFile::exists($path)) {
$formFile = $path;
}
}
}
}
if ($formFile) {
// If an XML file was found in the component, load it first.
// We need to qualify the full path to avoid collisions with component file names.
if ($form->loadFile($formFile, true, '/metadata') == false) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/metadata/layout/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$helpLoc = trim((string) $help[0]['local']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
$this->helpLocal = $helpLoc == 'true' || $helpLoc == '1' || $helpLoc == 'local' ? true : false;
}
}
// Now load the component params.
// TODO: Work out why 'fixing' this breaks JForm
if ($isNew = false) {
$path = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $option . '/config.xml');
} else {
$path = 'null';
}
if (JFile::exists($path)) {
// Add the component params last of all to the existing form.
if (!$form->load($path, true, '/config')) {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
//.........这里部分代码省略.........
示例10: preprocessForm
/**
* @param object $form A form object.
* @param mixed $data The data expected for the form.
*
* @return void
* @since 1.1.0
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$contentTypeID = $this->getState($this->getName() . '.content_type_id', 0);
if ($contentTypeID) {
$isNew = !(bool) $this->getState($this->getName() . '.id', 0);
$fieldsForm = new KextensionsForm($form->getName());
$fieldsData = FieldsandfiltersFieldsHelper::getFieldsByTypeIDColumnFieldType($contentTypeID);
$fieldsForm->setPath('filters');
$fieldsetXML = new SimpleXMLElement('<fieldset />');
$fieldsetXML->addAttribute('name', 'fieldsandfilters');
JPluginHelper::importPlugin('fieldsandfilterstypes');
// Trigger the onFieldsandfiltersPrepareFormField event.
JFactory::getApplication()->triggerEvent('onFieldsandfiltersPrepareFormField', array($fieldsForm, $fieldsData, $isNew));
if ($fieldsFormXML = $fieldsForm->getFormFields()) {
// Load the XML Helper
KextensionsXML::setFields($fieldsetXML, $fieldsFormXML);
$form->setField($fieldsetXML, 'fields');
if ($default = $fieldsForm->getData()) {
$form->bind($default);
}
}
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例11: preprocessForm
/**
* Method to preprocess the form
*
* @param JForm $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 1.6
* @throws Exception if there is an error loading the form.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
// Initialise variables.
$lang = Lang::getRoot();
$clientId = $this->getState('item.client_id');
$module = $this->getState('item.module');
$client = \Hubzero\Base\ClientManager::client($clientId);
//$formFile = JPath::clean($client->path.'/modules/'.$module.'/'.$module.'.xml');
$formFile = null;
$patha = JPath::clean(PATH_APP . '/modules/' . $module . '/' . $module . '.xml');
$pathc = JPath::clean(PATH_CORE . '/modules/' . $module . '/' . $module . '.xml');
if (file_exists($patha)) {
$formFile = $patha;
} elseif (file_exists($pathc)) {
$formFile = $pathc;
}
// Load the core and/or local language file(s).
$lang->load($module, PATH_APP . '/bootstrap/' . $client->name, null, false, true) || $lang->load($module, PATH_APP . '/modules/' . $module, null, false, true) || $lang->load($module, PATH_CORE . '/modules/' . $module, null, false, true);
if ($formFile) {
// Get the module form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/extension/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
}
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例12: preprocessForm
protected function preprocessForm(\JForm $form, $data, $group = 'content')
{
// if no data, grab the posted form data.
if (!$data instanceof JObject) {
$data = JFactory::getApplication()->input->get('jform', $data, 'array');
$data = JArrayHelper::toObject($data);
}
$params = new JRegistry();
$params->loadArray($data->params);
if ($params->get('discovery.url')) {
$plugin = $params->get('discovery.type');
$language = JFactory::getLanguage();
$language->load('plg_harvest_' . $plugin);
$path = JPATH_ROOT . '/plugins/harvest/' . $plugin . '/forms/harvest.xml';
$form->loadFile($path, false);
foreach (JPluginHelper::getPlugin('ingest') as $plugin) {
$language->load('plg_ingest_' . $plugin->name);
$path = JPATH_ROOT . '/plugins/ingest/' . $plugin->name . '/forms/ingest.xml';
$form->loadFile($path, false);
}
$form->removeField('originating_url');
$form->removeField('harvester');
// hide the run_once value (users cannot set it after discovery)
$form->setFieldAttribute("run_once", 'type', 'hidden');
$form->setFieldAttribute("run_once", 'class', '');
} else {
$form->removeField('state');
$form->removeField('harvested');
$form->removeField('url', 'params.discovery');
$form->removeField('type', 'params.discovery');
}
parent::preprocessForm($form, $data, $group);
}
示例13: preprocessForm
/**
* Method to allow derived classes to preprocess the form.
*
* @access protected
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
* @return void
*
* @since 12.2
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
$baseFolder = JPATH_COMPONENT . DS . 'fork' . DS . 'models' . DS . 'forms';
$formFile = $baseFolder . DS . $this->view_item . '.xml';
if (file_exists($formFile)) {
$xml = simplexml_load_file($formFile);
$form->load($xml, true);
}
parent::preprocessForm($form, $data, $group);
}
示例14: preprocessForm
/**
* Override JModelAdmin::preprocessForm to ensure the correct plugin group is loaded.
*
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 1.6
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
// Trigger the default form events.
parent::preprocessForm($form, $data, $plugin_type = '_none_');
// by default content plugins are imported, skip them
}
示例15: preprocessForm
protected function preprocessForm(JForm $form, $data, $group = 'djclassifiedsshipping')
{
return parent::preprocessForm($form, $data, $group);
}