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

OPENEUROPA-480: Provide a language selection page #5

Merged
merged 18 commits into from
May 29, 2018
Merged

Conversation

richardcanoe
Copy link
Contributor

OPENEUROPA-480

Description

Add sub module to implement and configure language selection page module.

composer.json Outdated
"php": "^7.1"
"drupal/devel": "^1.2",
"drupal/language_selection_page": "2.2",
"drupal/pathauto": "1.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no good reasons to lock the versions of the Language Selection Page and Pathauto modules, unless there is a known problem with a newer version. In that case this should be documented here (e.g. by using a "_readme" entry), and followup issues should be made to fix the bug and unlock the version again.

Drupal modules are not yet following semantic versioning (but this is in the works, ref. https://www.drupal.org/project/drupal/issues/1612910), but they do follow the core principles of semantic versioning: new minor versions of modules should only contain bug fixes and new features which do not break backwards compatibility. This means that it can be considered safe to unlock the versions, and it is recommended because it allows us to benefit from bugfixes and security fixes without making any changes to the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a policy or rule on when to use ^2.2 and when to use ~2.2 ? The current file has a mixture of both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfrenssen agreed, this will also allow site developers to fix the version they want to use in the site's composer.json, in case they need it, while if we lock them on the components' composer.json that would not be possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the ~2.2 and ^2.2 both are valid so they are both OK to be used. I don't think there is a need to define a policy because there is no "better" way to do this. Both cases are really easy to understand: the tilde updates only the most minor version specified, while the caret updates all versions except the most major one.

I personally prefer the tilde for dependencies that use a <major version>.<minor version> naming scheme such as Drupal modules. The caret is definitely the one to use for packages that adhere to semantic versioning <major version>.<minor version>.<patch>.

Some people like to use the caret for everything because it is "less confusing for newbies", but I think it is condescending to insinuate that young developers are not able to understand the difference between the two.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks 👍

I see that the drupal/administration_language_negotiation dependency is also locked but this is out of scope for this ticket, I created a followup to do this: OPENEUROPA-601.

composer.json Outdated
"drupal/drupal-extension": "^4.0.0@alpha",
"openeuropa/code-review": "^0.2",
"openeuropa/task-runner": "^0.5",
"openeuropa/oe_theme": "dev-master",
"openeuropa/oe_theme": "dev-OPENEUROPA-480",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR is merged we should get this sister branch in OE Theme merged so this can be reverted back to the master branch.

I would also propose to not rely on the master branch but instead making regular releases for the OE Theme. It is clear here that we are relying on a new feature that is being developed in OE Theme: the template for the language switcher. Since we depend on that feature this should be clearly indicated in our dependency list. This information is missing if we say that we depend on dev-master. Composer could very well decide to check out a fork or a cached version of the repository that doesn't include the template. The only reliable way to do this is:

  1. Accept and merge the sister PR in OE Theme.
  2. Tag a new release for the OE Theme: eg. 0.1.1 or 0.2.0.
  3. Indicate this version as the minimum version to use in our dependency graph: "openeuropa/oe_theme": "^0.1.1"

This way we can ensure that the actual template we depend on will be available, and Composer will refuse to build otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would always commit the theme and remove the branch as part of the final commit process. I agree that now the platform is evolving and growing we should start using minimum version increases for components.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agreed on not using dev-master anymore and tagging theme releases more often, especially after openeuropa/composer-artifacts#1 will be merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be taken care of before this is merged into the master branch, or this WILL break the master when the sister PR in OE Theme is merged and the corresponding branch deleted. If we don't address this then the dev-OPENEUROPA-480 branch will not be resolved by Composer, and it will not be able to build the dependencies.

The best way to handle tickets that require dependent changes in multiple components is to make subtasks for each component, and handle them separately. This allows to push the dependent changes through first, then tag a new release and use this in the depending component.

@@ -0,0 +1,19 @@
name: 'OpenEuropa Multilingual Selection Page'
type: module
description: 'Module for OpenEuropa Multilingual Language Selection Page.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to provide a short description of what the module does, rather than parroting the name of the module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed. Here's a suggestion for the description:

Provides a splash page that allows visitors to choose a language when they start browsing the website.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this has been addressed in the latest version of the PR. Approved! 👍

- field.field.node.oe_demo_translatable_page.field_oe_demo_translatable_body
- language.content_settings.node.oe_demo_translatable_page
- node.type.oe_demo_translatable_page
- pathauto.pattern.oe_demo_translatable_page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defines 7 config files but they are not present in the PR? Were these forgotten?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a copy/paste gone wrong since they are exported in the demo module and should be kept there indeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that explains it, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed, thanks 👍

'/admin*',
'/node/add/*',
'/node/*/edit',
])->save();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of setting configuration in an install hook, the recommended way to provide default configuration is by exporting it into a YAML file and placing it in the config/install subfolder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration is not provided by the oe_multilingual_selection_page so it cannot be stored in its config/install module, doing that will result in an error at installation time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config/optional then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have the same effect, the configuration is in the config/install of the module this module depends on, so that will be installed first, causing the same error.

Copy link
Member

@pfrenssen pfrenssen May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK let's go with the install hook, but there is a risk involved with this. If the site builder enables this module, then decides not to use it and uninstalls it again, the change to the language negotiation will not be undone. I would not suggest to revert to the previous language negotiation strategy either, since there might be a very long time between the enabling and uninstallation of the module, and the site may have become dependent on the language negotiation provided by this module.

What I think we need is a disclaimer / opt-in checkbox when enabling the module, and also documentation in the README that explains to site builders that enabling this module will set the administrative language to English.

Is there anything we can revert safely on hook_uninstall()? Maybe we can remove the language_selection_page.negotiation part from config and the LanguageNegotiationLanguageSelectionPage::METHOD_ID from the language negotiation?

I don't think we can touch the other things on uninstall though :-/

Providing a disclaimer and opt-in checkbox on installation is out of scope for this ticket, let's do this in a followup after discussion. We can put a @todo here though linking to the followup, and make a note in the README.

/**
* Helper service for language negotiation method configuration.
*/
class LanguageNegotiationSetter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's provide an interface for this service so that it can be overridden by custom implementations while still ensuring that the API stays the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, there is an interface now, thanks a lot! 👍

@@ -0,0 +1,73 @@
<?php

namespace Drupal\oe_multilingual;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets declare strict typing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks! 👍

* @param array $methods
* Array of language negotiation method names.
*/
public function enableNegotiationMethods(array $methods) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type declaration is missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks! 👍

* Enable given language negotiation methods.
*
* @param array $methods
* Array of language negotiation method names.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe provide an example here of how the passed data should look? By reading this documentation I have no idea of the kind of method names I should be passing in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK there is ample documentation now, thanks! 👍

* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope
* The Hook scope.
*
* @BeforeScenario @selection-page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice idea!

netlooker
netlooker previously approved these changes May 25, 2018
Copy link
Member

@netlooker netlooker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the PR and it looks good. Recent improvements are addressing most of the comments.

@ademarco ademarco changed the title Openeuropa 480 OPENEUROPA-480: Provide a language selection page May 28, 2018
Copy link
Member

@pfrenssen pfrenssen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good but we still need to fix the dependency on a PR branch in the OE Theme module, and mitigate the "dangerous" changes made to the language negotiation configuration when enabling the language selection page.

composer.json Outdated
"php": "^7.1"
"drupal/devel": "^1.2",
"drupal/language_selection_page": "2.2",
"drupal/pathauto": "1.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks 👍

I see that the drupal/administration_language_negotiation dependency is also locked but this is out of scope for this ticket, I created a followup to do this: OPENEUROPA-601.

composer.json Outdated
"drupal/drupal-extension": "^4.0.0@alpha",
"openeuropa/code-review": "^0.2",
"openeuropa/task-runner": "^0.5",
"openeuropa/oe_theme": "dev-master",
"openeuropa/oe_theme": "dev-OPENEUROPA-480",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be taken care of before this is merged into the master branch, or this WILL break the master when the sister PR in OE Theme is merged and the corresponding branch deleted. If we don't address this then the dev-OPENEUROPA-480 branch will not be resolved by Composer, and it will not be able to build the dependencies.

The best way to handle tickets that require dependent changes in multiple components is to make subtasks for each component, and handle them separately. This allows to push the dependent changes through first, then tag a new release and use this in the depending component.

@@ -0,0 +1,19 @@
name: 'OpenEuropa Multilingual Selection Page'
type: module
description: 'Module for OpenEuropa Multilingual Language Selection Page.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this has been addressed in the latest version of the PR. Approved! 👍

- field.field.node.oe_demo_translatable_page.field_oe_demo_translatable_body
- language.content_settings.node.oe_demo_translatable_page
- node.type.oe_demo_translatable_page
- pathauto.pattern.oe_demo_translatable_page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed, thanks 👍

/**
* Implements hook_install().
*/
function oe_multilingual_selection_page_install() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has not yet been addressed, but it is such a minor issue that I won't block acceptance on this.

->getCurrentLanguage()
->getId();

foreach ($variables['language_links']['#items'] as $key => $value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks! 👍

@@ -0,0 +1,73 @@
<?php

namespace Drupal\oe_multilingual;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks! 👍

/**
* Helper service for language negotiation method configuration.
*/
class LanguageNegotiationSetter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, there is an interface now, thanks a lot! 👍

* Enable given language negotiation methods.
*
* @param array $methods
* Array of language negotiation method names.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK there is ample documentation now, thanks! 👍

* @param array $methods
* Array of language negotiation method names.
*/
public function enableNegotiationMethods(array $methods) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed, thanks! 👍

@pfrenssen
Copy link
Member

OK so Github loses the context of my review comments because I have marked this as a "review" instead of normal comments. Very nice.

@pfrenssen
Copy link
Member

I have done review +1 on the OE Theme change, this can now be tagged with a new release, so this part can be unblocked.

@pfrenssen
Copy link
Member

There is a test failure due to insecure NPM dependencies, we need to address this too.

@pfrenssen
Copy link
Member

OK the disclaimer is good enough for me. Changes look good, will approve after test results are in.

$url = $value['#url']->toString();

$variables['languages'][] = [
"href" => $url,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use single quotes here.

"hreflang" => $language_code,
"label" => $value["#title"],
"lang" => $language_code,
"isActive" => $language_code === $current_language,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With ECL 1.0.0 this should be is_active.

pfrenssen
pfrenssen previously approved these changes May 29, 2018
@ademarco ademarco merged commit 4465652 into master May 29, 2018
@ademarco ademarco deleted the OPENEUROPA-480 branch May 29, 2018 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants