Skip to content

Commit 64d9bb2

Browse files
committed
Reload task belongs to the component controller
1 parent 48e2138 commit 64d9bb2

File tree

5 files changed

+90
-108
lines changed

5 files changed

+90
-108
lines changed

administrator/components/com_admin/script.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,8 @@ public function deleteUnexistingFiles()
18991899
'/administrator/templates/hathor/html/mod_menu',
19001900
'/administrator/components/com_messages/layouts/toolbar',
19011901
'/administrator/components/com_messages/layouts',
1902+
// Joomla! __DEPLOY_VERSION__
1903+
'/components/com_fields/controllers',
19021904
);
19031905

19041906
jimport('joomla.filesystem.file');

administrator/components/com_fields/controllers/field.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,6 @@ public function __construct($config = array())
4646
$this->component = $parts ? $parts[0] : null;
4747
}
4848

49-
/**
50-
* Stores the form data into the user state.
51-
*
52-
* @return void
53-
*
54-
* @since 3.7.0
55-
*/
56-
public function storeform()
57-
{
58-
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
59-
60-
$app = JFactory::getApplication();
61-
$data = $this->input->get($this->input->get('formcontrol', 'jform'), array(), 'array');
62-
63-
$parts = FieldsHelper::extract($this->input->getCmd('context'));
64-
65-
if ($parts)
66-
{
67-
$app->setUserState($parts[0] . '.edit.' . $parts[1] . '.data', $data);
68-
}
69-
70-
if ($this->input->get('userstatevariable'))
71-
{
72-
$app->setUserState($this->input->get('userstatevariable'), $data);
73-
}
74-
75-
$redirectUrl = base64_decode($this->input->get->getBase64('return'));
76-
77-
// Don't redirect to an external URL.
78-
If (!JUri::isInternal($redirectUrl))
79-
{
80-
$redirectUrl = 'index.php';
81-
}
82-
83-
$app->redirect($redirectUrl);
84-
$app->close();
85-
}
86-
8749
/**
8850
* Method override to check if you can add a new record.
8951
*

administrator/components/com_fields/helpers/fields.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -312,25 +312,6 @@ public static function prepareForm($context, JForm $form, $data)
312312
*/
313313
if ($form->getField('catid') && $parts[0] != 'com_fields')
314314
{
315-
// The uri to submit to
316-
$uri = clone JUri::getInstance('index.php');
317-
318-
/*
319-
* Removing the catid parameter from the actual URL and set it as
320-
* return
321-
*/
322-
$returnUri = clone JUri::getInstance();
323-
$returnUri->setVar('catid', null);
324-
$uri->setVar('return', base64_encode($returnUri->toString()));
325-
326-
// Setting the options
327-
$uri->setVar('option', 'com_fields');
328-
$uri->setVar('task', 'field.storeform');
329-
$uri->setVar('context', $parts[0] . '.' . $parts[1]);
330-
$uri->setVar('formcontrol', $form->getFormControl());
331-
$uri->setVar('view', null);
332-
$uri->setVar('layout', null);
333-
334315
/*
335316
* Setting the onchange event to reload the page when the category
336317
* has changed
@@ -343,8 +324,7 @@ function categoryHasChanged(element) {
343324
Joomla.loadingLayer('show');
344325
var cat = jQuery(element);
345326
if (cat.val() == '" . $assignedCatids . "')return;
346-
jQuery('input[name=task]').val('field.storeform');
347-
element.form.action='" . $uri . "';
327+
jQuery('input[name=task]').val('" . $section . ".reload');
348328
element.form.submit();
349329
}
350330
jQuery( document ).ready(function() {

components/com_fields/controllers/field.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

libraries/legacy/controller/form.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,4 +831,91 @@ public function save($key = null, $urlVar = null)
831831

832832
return true;
833833
}
834+
835+
/**
836+
* Method to reload a record.
837+
*
838+
* @param string $key The name of the primary key of the URL variable.
839+
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
840+
*
841+
* @return void
842+
*
843+
* @since __DEPLOY_VERSION__
844+
*/
845+
public function reload($key = null, $urlVar = null)
846+
{
847+
// Check for request forgeries.
848+
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
849+
850+
$app = JFactory::getApplication();
851+
$model = $this->getModel();
852+
$data = $this->input->post->get('jform', array(), 'array');
853+
854+
// Determine the name of the primary key for the data.
855+
if (empty($key))
856+
{
857+
$key = $model->getTable()->getKeyName();
858+
}
859+
860+
// To avoid data collisions the urlVar may be different from the primary key.
861+
if (empty($urlVar))
862+
{
863+
$urlVar = $key;
864+
}
865+
866+
$recordId = $this->input->getInt($urlVar);
867+
868+
// Populate the row id from the session.
869+
$data[$key] = $recordId;
870+
871+
// The redirect url
872+
$redirectUrl = JRoute::_(
873+
'index.php?option=' . $this->option . '&view=' . $this->view_item .
874+
$this->getRedirectToItemAppend($recordId, $urlVar),
875+
false
876+
);
877+
878+
// Validate the posted data.
879+
// Sometimes the form needs some posted data, such as for plugins and modules.
880+
$form = $model->getForm($data, false);
881+
882+
if (!$form)
883+
{
884+
$app->enqueueMessage($model->getError(), 'error');
885+
886+
$app->redirect($redirectUrl);
887+
$app->close();
888+
}
889+
890+
// Test whether the data is valid.
891+
$validData = $model->validate($form, $data);
892+
893+
// Check for validation errors.
894+
if ($validData === false)
895+
{
896+
// Get the validation messages.
897+
$errors = $model->getErrors();
898+
899+
// Push up to three validation messages out to the user.
900+
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
901+
{
902+
if ($errors[$i] instanceof Exception)
903+
{
904+
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
905+
}
906+
else
907+
{
908+
$app->enqueueMessage($errors[$i], 'warning');
909+
}
910+
}
911+
}
912+
else
913+
{
914+
// Save the data in the session.
915+
$app->setUserState($this->option . '.edit.' . $this->context . '.data', $validData);
916+
}
917+
918+
$app->redirect($redirectUrl);
919+
$app->close();
920+
}
834921
}

0 commit comments

Comments
 (0)