Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Feature] Multilingual: Propagating existing associations if desired #21321

Merged
merged 8 commits into from Aug 4, 2018

Conversation

@infograf768
Copy link
Member

@infograf768 infograf768 commented Jul 31, 2018

Pull Request for Issue #21250

Summary of Changes

This adds a "Propagate" button in the Associations tab when editing a contact, category, article, menu item, newsfeed.
This button will display when an association is selected in a Content Language field, offering the option to Propagate the associations defined for that item to the other Content Languages.

The button will display ONLY when there are more than 2 Content Languages defined for the site.
A message will display with the results obtained.

It is B/C as it will not break anything and one is totally free to choose or not to use the button, thus keeping the possibility to Clear/Select/Create any associations as before.

Using it prevents breaking existing associations when the wrong items are chosen for some fields.

A big thank you to Robbie Jackson for the long work to get this new functionality.
Target Milestone: 3.9.0

Testing Instructions

Create a Multilingual site with 3 or more languages.
Create items in each type: (contact, category, article, menu item, newsfeed) for 2 of these languages and associate them in each case.

Create a new item for each type, select another language than the ones which are already associated.
Save (NOT save and close) this item.
Display the Association tab.

You will see, as usual (here for 4 Content Languages)

screen shot 2018-07-31 at 11 13 04

I do have already associations set for English and French.

I select for English the item which I know is associated.

The button displays (Better tip welcome)

screen shot 2018-07-31 at 11 17 17

Clicking on the button will give

screen shot 2018-07-31 at 11 18 22

Result: the already associated category in French is added in the French field.
As we have no association set for Spanish, the field remains empty.
The message displays (it is the same in all cases except if there is an Ajax error)
All existing associations have been set. If some are missing you may have to select or create them manually.

If we have already associated all fields, clicking on Propagate will just display the message.

If we change an association in one of the fields and click Propagate, it is the associations from that language item that will be propagated and therefore replace the ones existing.

Documentation Changes Required

Yes

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Jul 31, 2018

the json files need corrections for cs. Can be tested and commented nevertheless. ;)

JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate"
JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE="All existing associations have been set. If some are missing you may have to select or create them manually."
JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this selected item existing associations."

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

Please correct to

"Propagates this item's existing associations."

@@ -281,6 +281,10 @@ JGLOBAL_ARTICLE_ORDER_DESC="The order that articles will show in."
JGLOBAL_ARTICLE_ORDER_LABEL="Article Order"
JGLOBAL_ARTICLES="Articles"
JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'."
JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate"
JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE="All existing associations have been set. If some are missing you may have to select or create them manually."

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

How likely is it that an association will be missing? Seems odd to me to have that on a success message.

This comment has been minimized.

@infograf768

infograf768 Jul 31, 2018
Author Member

It will happen when there is no item associated in a specific language. See image above where there is nothing for Spanish

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

so in that case nothing is missing as it doesnt exist
The first sentence is more than enough

This comment has been minimized.

@infograf768

infograf768 Jul 31, 2018
Author Member

This message is also informing the user that an association for one or more language(s) may be missing. It may be what the user wants but it also may not be.
In that case the user can select an item or create one directly in this interface.
This is important.

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

thats not the role of a success message.

This comment has been minimized.

@infograf768

infograf768 Jul 31, 2018
Author Member

It is only a success message for what could be propagated.

@@ -281,6 +281,10 @@ JGLOBAL_ARTICLE_ORDER_DESC="The order that articles will show in."
JGLOBAL_ARTICLE_ORDER_LABEL="Article Order"
JGLOBAL_ARTICLES="Articles"
JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'."
JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate"
JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually."

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

Shouldn't this be "will" not "may"?

This comment has been minimized.

@infograf768

infograf768 Jul 31, 2018
Author Member

Some one may not want to create associations for a specific language.
Change to ?
If desired, you will have to select or create them manually.

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

then they havent failed and this isnt a failure message

This comment has been minimized.

@infograf768

infograf768 Jul 31, 2018
Author Member

Propagate has failed (for an unknown reason. It may be the case for a 3rd party component which is badly coded). It does not mean the user lost the possibility to associate items by selecting/creating them.

I am now waiting for tests. Thank you.

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

ok change to your suggestion of "If desired, you will have to select or create them manually.

infograf768 added 2 commits Jul 31, 2018
cs
@brianteeman
Copy link
Member

@brianteeman brianteeman commented Jul 31, 2018

Testing this and my only issue is with the messages

The propagate button says

Propagate this items existing associations

But you always get this message

All existing associations have been set. If some are missing you may have to select or create them manually.

The code should check to see if there any associations to propagate and if not then the message should be

No associations exist to propagate

And if there are associations to propagate then the message should be

All existing associations have been set.

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Jul 31, 2018

We will now get 3 types of messages:
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL="All existing associations have been set."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Some associations have been set: %s"

JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME will also display the language(s) where associations have been added.

Example. Here I selected an article for English. It added the French existing association, but as the Spanish one did not exist, it is that message which is used displaying which association was set.
screen shot 2018-07-31 at 16 34 41

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Jul 31, 2018

Restarted drone who failed on js.

JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL="All existing associations have been set."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate."
JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Some associations have been set: %s"

This comment has been minimized.

@brianteeman

brianteeman Jul 31, 2018
Member

Please change to
Associations have been set for: %s

@brianteeman
Copy link
Member

@brianteeman brianteeman commented Jul 31, 2018

Much better now.

I am also getting a missing string JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Jul 31, 2018

done

@jreys
Copy link
Contributor

@jreys jreys commented Aug 1, 2018

I have tested this item successfully on eabc256


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

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 1, 2018

One more tester.

$associations[$lang]->title = $categoryTable->title;
}

$message = null;

This comment has been minimized.

@Quy

Quy Aug 1, 2018
Contributor

Remove. Not necessary as it will be assigned later in the if statement.

This comment has been minimized.

@infograf768

infograf768 Aug 1, 2018
Author Member

Waiting for other comments from you before changing. 👍

This comment has been minimized.

@Quy

Quy Aug 1, 2018
Contributor

Repeat this change in the other files.

@@ -169,6 +176,23 @@ function jSelectNewsfeed_" . $this->id . "(id, title, object) {
. '</a>';
}

// Propagate contact button

This comment has been minimized.

@Quy

Quy Aug 1, 2018
Contributor

Update comment.

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 1, 2018

@Quy
All done. Thanks.

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 1, 2018

@Quy @franz-wohlkoenig @brianteeman
Please add your tests.

@ghost
Copy link

@ghost ghost commented Aug 1, 2018

@infograf768 have read Instructions a few Times but didn't understand really what is to test. So i need Time.

@ghost
Copy link

@ghost ghost commented Aug 2, 2018

I have tested this item successfully on b902d37


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

@ghost
Copy link

@ghost ghost commented Aug 2, 2018

Ready to Commit after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC label Aug 2, 2018
@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 2, 2018

@mbabker
I have tagged this to 3.9. Can you merge?

@@ -101,6 +101,7 @@
<?php echo $this->form->getInput('extension'); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo '<input id="token" type="hidden" name="' . JSession::getFormToken() . '" value="1" />'; ?>

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

This line shouldn't be necessary, this is exactly what the JHtml call immediately below does.

@@ -120,5 +120,6 @@
</div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo '<input id="token" type="hidden" name="' . JSession::getFormToken() . '" value="1" />'; ?>

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

Same as above.

@@ -138,6 +138,7 @@
<input type="hidden" name="task" value="" />
<input type="hidden" name="return" value="<?php echo $input->getCmd('return'); ?>" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo '<input id="token" type="hidden" name="' . JSession::getFormToken() . '" value="1" />'; ?>

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

Same as above.

@@ -232,6 +232,7 @@

<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo '<input id="token" type="hidden" name="' . JSession::getFormToken() . '" value="1" />'; ?>

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

Same as above.

@@ -107,5 +107,6 @@
</div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo '<input id="token" type="hidden" name="' . JSession::getFormToken() . '" value="1" />'; ?>

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

Same as above.

var currentLang = jQuery('#jform_language').find(":selected").val();

// Find the token so that it can be sent in the Ajax request as well
var token = jQuery("#token").attr("name");

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

Instead of finding the token in this way, the API added in #14952 should be used instead.

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

You mean using
var token = jQuery('meta[name=csrf-token]').val(); instead?

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

hmm, that does not work

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

In the layouts, you have to add a JHtml::_('jquery.token'); call, then you don't even need to find the token and manually include it when using jQuery.ajax because that PHP call will set up jQuery to include the token automatically.

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

This works.
var token = Joomla.getOptions('csrf.token', '');

Is that OK, @mbabker ?

This comment has been minimized.

@mbabker

mbabker Aug 2, 2018
Contributor

Yes.

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

I did not add the <?php echo JHtml::_('jquery.token'); ?>
Just deleted the extraneous lines in the edit.php and used
var token = Joomla.getOptions('csrf.token', '');

As I did not know what would be the consequences

Can we go with that?

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 2, 2018

@mbabker
Do we need new tests?

*
* @since __DEPLOY_VERSION__
*/
window.injectAssociations = function(result, callbackFunctionPrefix)

This comment has been minimized.

@dgrammatiko

dgrammatiko Aug 2, 2018
Contributor

This is really bad. Please name this as Joomla.injectAssociations. Global variables, functions etc are as bad in Javascipt as they are in PHP 👎

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

I guess Robbie used this as we have above existing
window.hideAssociation
and
window.showAssociationMessage

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

I guess I found what has to be modifed to fit as both the functions use window.
It is not the purpose of this patch to also correct the existing ones.

This comment has been minimized.

@infograf768

infograf768 Aug 2, 2018
Author Member

@dgrammatiko
Do you agree with my statement?
If yes, I will do the patch right now

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 3, 2018

@dgrammatiko
Modified the new js functions name as required.
We can't obviously normalize the others as it would not be B/C.

@franz-wohlkoenig @jreys
Please test again. :)

@joomla-cms-bot joomla-cms-bot removed this from the Joomla 3.9.0 milestone Aug 4, 2018
@ghost
Copy link

@ghost ghost commented Aug 4, 2018

I have tested this item successfully on 888a280


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

@joomla-cms-bot joomla-cms-bot removed the RTC label Aug 4, 2018
@infograf768 infograf768 added this to the Joomla 3.9.0 milestone Aug 4, 2018
@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 4, 2018

@mbabker Can you now merge?

@mbabker mbabker merged commit 8bacca9 into joomla:staging Aug 4, 2018
4 of 5 checks passed
4 of 5 checks passed
JTracker/HumanTestResults Human Test Results: 1 Successful 0 Failed.
Details
Hound No violations found. Woof!
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/drone/pr the build was successful
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 4, 2018

@mbabker
As it is a new feature, shall not it be merged in 3.9.0 ?

@mbabker
Copy link
Contributor

@mbabker mbabker commented Aug 4, 2018

💩

mbabker added a commit that referenced this pull request Aug 4, 2018
… if desired (#21321)"

This reverts commit 8bacca9.
mbabker added a commit that referenced this pull request Aug 4, 2018
Michael Babker
… if desired (#21321)" (#21408)

This reverts commit 8bacca9.
@mbabker
Copy link
Contributor

@mbabker mbabker commented Aug 4, 2018

Branch merged to 3.9-dev via 11153f7

@infograf768
Copy link
Member Author

@infograf768 infograf768 commented Aug 4, 2018

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.