?
avatar Quy
Quy
7 Nov 2019

Steps to reproduce the issue

Install a multilingual site (English & French).
Edit an article that has language All and change it to English.
Click Associations button.
View PHP error log.

Actual result

PHP Notice: Undefined index: associations in \libraries\src\MVC\Model\AdminModel.php on line 1713

System information (as much as possible)

Additional comments

avatar Quy Quy - open - 7 Nov 2019
avatar joomla-cms-bot joomla-cms-bot - change - 7 Nov 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 7 Nov 2019
avatar infograf768
infograf768 - comment - 8 Nov 2019

The Notice displays if we have only 2 languages.
The Associations button is the Toolbar button, not the Associations tab. It loads the side-by-side com_associations page.

		/*
		 * If the site contains only 2 languages and an association exists for the item
		 * load directly the associated target item in the side by side view
		 * otherwise select already the target language
		 */

The issue comes from the fact that the article is temporarily considered as set to ALL languages when getting to com_associations side-by-side because the article has not been saved yet to English.
Once displayed in the side-by-side its language is correctly set as the article is automatically saved in the method.

		// Save the item
		$this->save($data);

Let's go a bit further into this.
If the article (saved) is set to All languages and we click on the Associations Toolbar, we correctly get a Notice.

Notice

To define associations, please make sure the item language is not set to 'All'.

It comes from the string
JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'."

We do have another string that should be used if the language is modified from All languages to English without saving first when clicking on the Associations Toolbar button. It is:
JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING="To create associations, first save the item."

But this error would only be displayed if it's a new article ($id == 0).

The solution is to force that message to displayed.

Screen Shot 2019-11-08 at 09 30 34

But we must be aware that when message is displayed, the article has already been saved and therefore is already set to English.

Therefore, to get rid of the Notice the modified code would be

			if (isset($data['associations'][$targetLang]))
			{
				$targetId   = $data['associations'][$targetLang];
			}
			else
			{
				$app->enqueueMessage(Text::_('JGLOBAL_ASSOCIATIONS_NEW_ITEM_WARNING'), 'error');
				$app->redirect(
					Route::_('index.php?option=' . $component . '&view=' . $view . $client . '&layout=edit&id=' . $id . $extension, false)
				);

				return false;
			}

We also could create a new Message.
Something like:
"The item language has now been saved. Please try again."

I can make the PR. What you think?

Note:
We have also an issue with the Associations Tab where a message should display when the language is set to All. Independant from this one.

avatar infograf768
infograf768 - comment - 8 Nov 2019

About my Note above:
someone has added in the edit.php for all components an $hasAssoc variable which prevents displaying the Notice in the Associations Tab. GRRR...

avatar infograf768
infograf768 - comment - 8 Nov 2019

It was done before merging the new admin template.
@Hackwar
Why have you done that? We now have an empty tab when language is set to All instead of the Notice which is provided by js!

We should get
Screen Shot 2019-11-08 at 12 01 34

And now we get
Screen Shot 2019-11-08 at 12 03 56

avatar infograf768
infograf768 - comment - 8 Nov 2019

Will make PR for the Associations Tab.
Waiting for @Quy concerning the original issue

avatar Quy
Quy - comment - 8 Nov 2019

With PR #27023 applied, the following alert is displayed. No notice in PHP error log when clicking the Associations button. Please confirm to close this issue.

The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item.

avatar infograf768
infograf768 - comment - 8 Nov 2019

@Quy
on ipad now. will test tomorrow.

avatar infograf768 infograf768 - change - 9 Nov 2019
Status New Closed
Closed_Date 0000-00-00 00:00:00 2019-11-09 06:20:39
Closed_By infograf768
avatar infograf768
infograf768 - comment - 9 Nov 2019

Weird but true. ;) Closing.

avatar infograf768 infograf768 - close - 9 Nov 2019

Add a Comment

Login with GitHub to post a comment