? ? ? Failure

User tests: Successful: Unsuccessful:

avatar bembelimen
bembelimen
25 Nov 2016

Summary of Changes

If you create a frontend article submission, you cannot specify, where the user will be redirected after the submission. As default, the user will be redirected to the frontpage. With this patch, you can define a menu item where the user should be redirected or still use the default behavior.

Testing Instructions

=> Create a frontend submission menu item
=> Look in the tab "options"
=> There should be no parameter
=> Submit an article in the frontend, you'll redirected to the front page
=> Apply patch
=> Look into the menu item options again, there should be a new parameter
=> Let it at "default" and submit a new article, the redirect to the frontpage should still work
=> Choose a new redirect target in the menu item option
=> Submit an article
=> The user should be redirected to the new (defined) target

avatar bembelimen bembelimen - open - 25 Nov 2016
avatar bembelimen bembelimen - change - 25 Nov 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 25 Nov 2016
Category Administration Language & Strings Front End com_content
avatar bembelimen bembelimen - change - 25 Nov 2016
Title
Patch 15
add redirect option after article submission
avatar bembelimen bembelimen - edited - 25 Nov 2016
avatar bembelimen bembelimen - change - 25 Nov 2016
Title
Patch 15
add redirect option after article submission
avatar bembelimen bembelimen - change - 25 Nov 2016
Labels Added: ?
avatar chmst
chmst - comment - 25 Nov 2016

I have tested this item successfully on 1532ea3


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar chmst chmst - test_item - 25 Nov 2016 - Tested successfully
avatar brianteeman
brianteeman - comment - 25 Nov 2016

I have tested this item successfully on d3676f1

Nice idea - works great


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar brianteeman brianteeman - test_item - 25 Nov 2016 - Tested successfully
avatar infograf768
infograf768 - comment - 25 Nov 2016
  1. Please use the new modal_menu as type and not menuitem
  2. Also, this is not taking into account the language when in multilanguage.
    See code example here: https://github.com/joomla/joomla-cms/blob/staging/components/com_users/controllers/user.php#L28

The string would also have to be changed to fit: see string in com_users

avatar infograf768
infograf768 - comment - 25 Nov 2016

I have tested this item ? unsuccessfully on d3676f1


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar infograf768 infograf768 - test_item - 25 Nov 2016 - Tested unsuccessfully
avatar bembelimen bembelimen - change - 25 Nov 2016
Labels Removed: ?
avatar bembelimen bembelimen - change - 25 Nov 2016
Labels Added: ?
avatar bembelimen
bembelimen - comment - 25 Nov 2016

After discussing with @infograf768 we found some issues with the new field, which I will rewrite.

avatar JoshuaLewis
JoshuaLewis - comment - 27 Nov 2016

Looking forward to testing this once the issues are fixed. This is a big step in the right direction. Not sure if it's feasible at the moment, but would be really amazing to have a redirect option to the newly submitted article as well. Typically people want to review their submission after submitting it to the public. I understand that some sites have the content go under pending review, hence why the administrator would make the decision on what the right view is.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar brianteeman
brianteeman - comment - 4 Dec 2016

@bembelimen what is the status with this?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar brianteeman brianteeman - change - 4 Dec 2016
Status Pending Information Required
avatar bembelimen
bembelimen - comment - 5 Dec 2016

Hi @brianteeman here are the first changes for the field improvements: #13085

avatar bembelimen
bembelimen - comment - 5 Dec 2016

@infograf768 is there a reason why you make this complex call here: https://github.com/joomla/joomla-cms/blob/staging/components/com_users/controllers/user.php#L47 instead of using JFactory::getApplication()->getMenu()->getItem(xxx);? If yes,I have to change my code...

avatar bembelimen bembelimen - change - 5 Dec 2016
Labels Added: ?
avatar infograf768
infograf768 - comment - 5 Dec 2016

is there a reason why you make this complex call here

it could be simplified indeed but the params we have for the login menu item may or may not be numeric.
It's much simpler in the module
https://github.com/joomla/joomla-cms/blob/staging/modules/mod_login/helper.php#L30-L51

avatar coolcat-creations
coolcat-creations - comment - 9 Dec 2016

I have tested this item ? unsuccessfully on 5ccb0f1

I selected content component and instead of beeing redirected to /index.php/en/content-component if was redirected to /index.php/en/?Itemid=266

then i tested to redirect to http://localhost:8888/joomla-cms/index.php/en/sample-sites but was redirected to the frontpage.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar coolcat-creations coolcat-creations - test_item - 9 Dec 2016 - Tested unsuccessfully
avatar infograf768
infograf768 - comment - 13 Dec 2016

I have tested this item ? unsuccessfully on 5ccb0f1

Does not work here. I tested redirecting to a menu item in another language than the page which contains the Create article form.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

avatar infograf768 infograf768 - test_item - 13 Dec 2016 - Tested unsuccessfully
avatar infograf768
infograf768 - comment - 14 Dec 2016

@bembelimen
I could solve the issue here by using JRoute in the controller, i.e.

	/**
	 * Method to save 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  boolean  True if successful, false otherwise.
	 *
	 * @since   1.6
	 */
	public function save($key = null, $urlVar = 'a_id')
	{
		$result = parent::save($key, $urlVar);

		// If ok, redirect to the return page.
		if ($result)
		{
			$this->setRedirect(JRoute::_($this->getReturnPage()));
		}

		return $result;
	}

remains to decide if it is better to add the rest of the code in populateState() with all these encode/decode and not simply in the getReturnPage() method.

If I do that, this is the .diff I get:

diff --git a/administrator/language/en-GB/en-GB.com_content.ini b/administrator/language/en-GB/en-GB.com_content.ini
index bca7ff1..6d2e065 100644
--- a/administrator/language/en-GB/en-GB.com_content.ini
+++ b/administrator/language/en-GB/en-GB.com_content.ini
@@ -32,4 +32,6 @@
 COM_CONTENT_CREATE_ARTICLE_CATEGORY_LABEL="Default Category"
 COM_CONTENT_CREATE_ARTICLE_CATEGORY_DESC="If set to 'Yes', this page will only let you create articles in the category selected below."
+COM_CONTENT_CREATE_ARTICLE_REDIRECTMENU_DESC="Select or create the page the user will be redirected to after a successful article submission. The default is to redirect to the home page."
+COM_CONTENT_CREATE_ARTICLE_REDIRECTMENU_LABEL="Submission Redirect"
 COM_CONTENT_DRILL_CATEGORIES_LABEL="List or Blog: after choosing the display,<br />make sure you define the Options in the desired layout."
 COM_CONTENT_DRILL_DOWN_LAYOUT_DESC="When drilling down to a category, show articles in a list or blog layout."
diff --git a/components/com_content/controllers/article.php b/components/com_content/controllers/article.php
index c28a71d..2048fbf 100644
--- a/components/com_content/controllers/article.php
+++ b/components/com_content/controllers/article.php
@@ -307,5 +307,5 @@
 		if ($result)
 		{
-			$this->setRedirect($this->getReturnPage());
+			$this->setRedirect(JRoute::_($this->getReturnPage()));
 		}
 
diff --git a/components/com_content/models/form.php b/components/com_content/models/form.php
index f8301e3..626f2b3 100644
--- a/components/com_content/models/form.php
+++ b/components/com_content/models/form.php
@@ -163,4 +163,32 @@
 	public function getReturnPage()
 	{
+		$app = JFactory::getApplication();
+
+		// Load the parameters.
+		$params = $app->getParams();
+		$this->setState('params', $params);
+
+		$menuitem = (int) $params->get('redirect_menuitem');
+
+		// Check for redirection after submission
+		if ($menuitem > 0)
+		{
+			$lang = '';
+
+			if (JLanguageMultilang::isEnabled())
+			{
+				$item = $app->getMenu()->getItem($menuitem);
+
+				$lang =  !is_null($item) && $item->language != '*' ? '&lang=' . $item->language : '';
+			}
+
+			$return = 'index.php?Itemid=' . $menuitem . $lang;
+
+			if (JUri::isInternal($return))
+			{
+				$this->setState('return_page', $return);
+			}
+		}
+
 		return base64_encode($this->getState('return_page'));
 	}
diff --git a/components/com_content/views/form/tmpl/edit.xml b/components/com_content/views/form/tmpl/edit.xml
index c82a1aa..76ee980 100644
--- a/components/com_content/views/form/tmpl/edit.xml
+++ b/components/com_content/views/form/tmpl/edit.xml
@@ -26,5 +26,14 @@
 				description="JGLOBAL_CHOOSE_CATEGORY_DESC" 
 				showon="enable_category:1" />
+
+			<field
+				name="redirect_menuitem"
+				type="modal_menu"
+				label="COM_CONTENT_CREATE_ARTICLE_REDIRECTMENU_LABEL"
+				description="COM_CONTENT_CREATE_ARTICLE_REDIRECTMENU_DESC"
+			>
+				<option value="">JDEFAULT</option>
+			</field>
 		</fieldset>
 	</fields>
-</metadata>
\ No newline at end of file
+</metadata>

redirect_submission.txt

avatar infograf768
infograf768 - comment - 14 Dec 2016

After a discussion with @Bakual I guess we should do all in the controller

avatar Bakual
Bakual - comment - 14 Dec 2016

The models job is the data manipulation and browser behavior doesn't exactly fall into that category :)
So yes, imho, deciding to which page that should redirected is a job of the controller.

Since you only want to redirect to that new menu item after a successful save, it has to be in that save method (after the check for a successful save) as JM suggested.

avatar infograf768
infograf768 - comment - 15 Dec 2016

@bembelimen
I can work on this if you like.
We also have to deal with the following issue while doing this:
See: #12687

avatar joomla-cms-bot joomla-cms-bot - change - 15 Dec 2016
Closed_Date 2016-12-15 12:07:11 2016-12-15 12:07:12
Closed_By infograf768 joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 15 Dec 2016
avatar joomla-cms-bot joomla-cms-bot - close - 15 Dec 2016
avatar infograf768 infograf768 - change - 15 Dec 2016
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2016-12-15 12:07:11
Closed_By infograf768
avatar joomla-cms-bot
joomla-cms-bot - comment - 15 Dec 2016
avatar infograf768
infograf768 - comment - 15 Dec 2016

Closing in favour of #13228


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13011.

Add a Comment

Login with GitHub to post a comment