User tests: Successful: 2 chmst, matrikular Unsuccessful: 0
At the moment, the JApplicationCms class allows us to retrive all messages attached to the object via $app->getMessageQueue()
. This method clears the messages from the session, so we'll get no duplicates (what is great), but the methods also attach/keeps the messages itself. So after a redirect all the messages will be outputted again. (https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/application/cms.php#L1052).
This is very unhandy, if you want to change the error messages, like (as easy example):
$app = JFactory::getApplication();
$messages = $app->getMessageQueue();
foreach ($messages as $message)
{
$app->enqueueMessage('Prefix: ' . $message['message'], $message['type']);
}
The complex picture where this could appear is:
onUserBeforeSave
and an onContentPrepareForm
event.onContentPrepareForm
extends the user profile form with a image uploadonUserBeforeSave
validates the file with the JMediaHelper classThe problem is now: if an error raises in the JHelperMedia class (https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/helper/media.php), it will use $app->enqueMessage(...)
to "communicate" this errors (e.g. https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/helper/media.php#L59). The profile saving method looks for errors in the user model and attach a prefix (https://github.com/joomla/joomla-cms/blob/staging/components/com_users/controllers/profile.php#L162), so any plugin has to raise/throw it's own errors to interact with this call (https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/user/user.php#L786).
So the way is:
$app->getMessageQueue()
for existing errors and throw themSolution: see this patch. An additional parameter which clears the application message queue and prevent double output.
Call somewhere
$app = JFactory::getApplication();
$app->enqueueMessage('Foo', 'notice');
$app->getMessageQueue(true);
$app->redirect(JRoute::_('index.php'));
The message does not appear
The message appears
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
I have tested this item
Patch works as described - Joomla! 3.6.5
It is to mention though, that I had to apply the changes in JApplicationCms::getMessageQueue manually. I wasn't able to apply the patch via patchtester.
@matrikular: I've tested on 3.7.0 beta2 using the patch tester.
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-02-12 15:51:02 |
Closed_By | ⇒ | rdeutz | |
Labels |
Added:
?
|
I have tested this item✅ successfully on f551d1f
I've tested this successfull following the testing instructions. I used the view of the administrator - com_content - article to insert the sample code. Then it works as described.
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13975.