diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 7f919708b3c84..8247bae5fe141 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -497,6 +497,7 @@ public function deleteUnexistingFiles() '/components/com_media/controller.php', '/components/com_media/helpers/index.html', '/components/com_media/helpers/media.php', + '/components/com_fields/controllers/field.php', // Joomla 3.0 '/administrator/components/com_admin/sql/updates/mysql/1.7.0-2011-06-06-2.sql', '/administrator/components/com_admin/sql/updates/mysql/1.7.0-2011-06-06.sql', @@ -1723,6 +1724,8 @@ public function deleteUnexistingFiles() '/administrator/templates/hathor/html/mod_menu', '/administrator/components/com_messages/layouts/toolbar', '/administrator/components/com_messages/layouts', + // Joomla! __DEPLOY_VERSION__ + '/components/com_fields/controllers', ); jimport('joomla.filesystem.file'); diff --git a/administrator/components/com_fields/controllers/field.php b/administrator/components/com_fields/controllers/field.php index d2205e87d837a..4d75638dda8aa 100644 --- a/administrator/components/com_fields/controllers/field.php +++ b/administrator/components/com_fields/controllers/field.php @@ -46,44 +46,6 @@ public function __construct($config = array()) $this->component = $parts ? $parts[0] : null; } - /** - * Stores the form data into the user state. - * - * @return void - * - * @since 3.7.0 - */ - public function storeform() - { - JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); - - $app = JFactory::getApplication(); - $data = $this->input->get($this->input->get('formcontrol', 'jform'), array(), 'array'); - - $parts = FieldsHelper::extract($this->input->getCmd('context')); - - if ($parts) - { - $app->setUserState($parts[0] . '.edit.' . $parts[1] . '.data', $data); - } - - if ($this->input->get('userstatevariable')) - { - $app->setUserState($this->input->get('userstatevariable'), $data); - } - - $redirectUrl = base64_decode($this->input->get->getBase64('return')); - - // Don't redirect to an external URL. - If (!JUri::isInternal($redirectUrl)) - { - $redirectUrl = 'index.php'; - } - - $app->redirect($redirectUrl); - $app->close(); - } - /** * Method override to check if you can add a new record. * diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index a8ef2c0c869c6..d20333c74aa54 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -314,25 +314,6 @@ public static function prepareForm($context, JForm $form, $data) */ if ($form->getField('catid') && $parts[0] != 'com_fields') { - // The uri to submit to - $uri = clone JUri::getInstance('index.php'); - - /* - * Removing the catid parameter from the actual URL and set it as - * return - */ - $returnUri = clone JUri::getInstance(); - $returnUri->setVar('catid', null); - $uri->setVar('return', base64_encode($returnUri->toString())); - - // Setting the options - $uri->setVar('option', 'com_fields'); - $uri->setVar('task', 'field.storeform'); - $uri->setVar('context', $parts[0] . '.' . $parts[1]); - $uri->setVar('formcontrol', $form->getFormControl()); - $uri->setVar('view', null); - $uri->setVar('layout', null); - /* * Setting the onchange event to reload the page when the category * has changed @@ -345,8 +326,7 @@ function categoryHasChanged(element) { var cat = jQuery(element); if (cat.val() == '" . $assignedCatids . "')return; Joomla.loadingLayer('show'); - jQuery('input[name=task]').val('field.storeform'); - element.form.action='" . $uri . "'; + jQuery('input[name=task]').val('" . $section . ".reload'); element.form.submit(); } jQuery( document ).ready(function() { diff --git a/administrator/components/com_fields/models/fields/type.php b/administrator/components/com_fields/models/fields/type.php index aa24240595cdb..d7f0ed7dbc494 100644 --- a/administrator/components/com_fields/models/fields/type.php +++ b/administrator/components/com_fields/models/fields/type.php @@ -68,25 +68,6 @@ function ($a, $b) } ); - // Reload the page when the type changes - $uri = clone JUri::getInstance('index.php'); - - // Removing the catid parameter from the actual URL and set it as - // return - $returnUri = clone JUri::getInstance(); - $returnUri->setVar('catid', null); - $uri->setVar('return', base64_encode($returnUri->toString())); - - // Setting the options - $uri->setVar('option', 'com_fields'); - $uri->setVar('task', 'field.storeform'); - $uri->setVar('context', 'com_fields.field'); - $uri->setVar('formcontrol', $this->form->getFormControl()); - $uri->setVar('userstatevariable', 'com_fields.edit.field.data'); - $uri->setVar('view', null); - $uri->setVar('layout', null); - - JFactory::getDocument()->addScriptDeclaration(" jQuery( document ).ready(function() { Joomla.loadingLayer('load'); @@ -94,8 +75,7 @@ function ($a, $b) function typeHasChanged(element){ Joomla.loadingLayer('show'); var cat = jQuery(element); - jQuery('input[name=task]').val('field.storeform'); - element.form.action='" . $uri . "'; + jQuery('input[name=task]').val('field.reload'); element.form.submit(); } "); diff --git a/components/com_fields/controllers/field.php b/components/com_fields/controllers/field.php deleted file mode 100644 index b37183e29fdcf..0000000000000 --- a/components/com_fields/controllers/field.php +++ /dev/null @@ -1,49 +0,0 @@ -input->get($this->input->get('formcontrol', 'jform'), array(), 'array'); - $parts = FieldsHelper::extract($this->input->getCmd('context')); - - if ($parts) - { - $app->setUserState($parts[0] . '.edit.' . $parts[1] . '.data', $data); - } - - $redirectUrl = base64_decode($this->input->get->getBase64('return')); - - // Don't redirect to an external URL. - If (!JUri::isInternal($redirectUrl)) - { - $redirectUrl = 'index.php'; - } - - $app->redirect($redirectUrl); - $app->close(); - } -} diff --git a/libraries/legacy/controller/form.php b/libraries/legacy/controller/form.php index 9b960faa5d844..26fe3071a6d4f 100644 --- a/libraries/legacy/controller/form.php +++ b/libraries/legacy/controller/form.php @@ -844,4 +844,77 @@ public function save($key = null, $urlVar = null) return true; } + + /** + * Method to reload a record. + * + * @param string $key The name of the primary key of the URL variable. + * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function reload($key = null, $urlVar = null) + { + // Check for request forgeries. + JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + $app = JFactory::getApplication(); + $model = $this->getModel(); + $data = $this->input->post->get('jform', array(), 'array'); + + // Determine the name of the primary key for the data. + if (empty($key)) + { + $key = $model->getTable()->getKeyName(); + } + + // To avoid data collisions the urlVar may be different from the primary key. + if (empty($urlVar)) + { + $urlVar = $key; + } + + $recordId = $this->input->getInt($urlVar); + + if (!$this->allowEdit($data, $key)) + { + $this->setRedirect( + JRoute::_( + 'index.php?option=' . $this->option . '&view=' . $this->view_list + . $this->getRedirectToListAppend(), false + ) + ); + $this->redirect(); + } + + // Populate the row id from the session. + $data[$key] = $recordId; + + // The redirect url + $redirectUrl = JRoute::_( + 'index.php?option=' . $this->option . '&view=' . $this->view_item . + $this->getRedirectToItemAppend($recordId, $urlVar), + false + ); + + // Validate the posted data. + // Sometimes the form needs some posted data, such as for plugins and modules. + $form = $model->getForm($data, false); + + if (!$form) + { + $app->enqueueMessage($model->getError(), 'error'); + + $this->setRedirect($redirectUrl); + $this->redirect(); + } + + // Save the data in the session. + $app->setUserState($this->option . '.edit.' . $this->context . '.data', $form->filter($data)); + + $this->setRedirect($redirectUrl); + $this->redirect(); + } }