User tests: Successful: Unsuccessful:
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.
=> 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
Status | New | ⇒ | Pending |
Category | ⇒ | Administration Language & Strings Front End com_content |
Title |
|
Title |
|
Labels |
Added:
?
|
I have tested this item
Nice idea - works great
The string would also have to be changed to fit: see string in com_users
I have tested this item
Labels |
Removed:
?
|
Labels |
Added:
?
|
After discussing with @infograf768 we found some issues with the new field, which I will rewrite.
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.
@bembelimen what is the status with this?
Status | Pending | ⇒ | Information Required |
Hi @brianteeman here are the first changes for the field improvements: #13085
@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...
Labels |
Added:
?
|
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
I have tested this item
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.
I have tested this item
Does not work here. I tested redirecting to a menu item in another language than the page which contains the Create article form.
@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>
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.
@bembelimen
I can work on this if you like.
We also have to deal with the following issue while doing this:
See: #12687
Closed_Date | 2016-12-15 12:07:11 | ⇒ | 2016-12-15 12:07:12 |
Closed_By | infograf768 | ⇒ | joomla-cms-bot |
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-12-15 12:07:11 |
Closed_By | ⇒ | infograf768 |
Set to "closed" on behalf of @infograf768 by The JTracker Application at issues.joomla.org/joomla-cms/13011
Closing in favour of #13228
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.