Is it possible to specify different destination paths based on the language of the source page (one time login link form in my case)?

Ideally each rule would let us specify an interface language the rule would apply for, similarly to how it filters based on path and role. Alternatively the ability to translate a rule would be great, but ultimately that works out to the same thing I think.

Comments

alienzed created an issue. See original summary.

alienzed’s picture

StatusFileSize
new4.34 KB

I've added this in and it works for me... I am not super familiar with getting these types of changes into modules, so any and all help would be much appreciated.

alienzed’s picture

StatusFileSize
new4.37 KB
alienzed’s picture

StatusFileSize
new4.3 KB
rsvelko’s picture

The patch looks good on first sight.
Let's give a week to the community to test it with sites using i18n and sites w/o i18n.
I'll test myself on two test sites.
Also I will try and find out if we need to write update hooks for existing module installs.

Thanks for the patch, @alienzed! After a bit of testing and review, it will be committed.

megachriz’s picture

The patch does add some coding standard violations. https://www.drupal.org/pift-ci-job/1225168 says that there are nine more.

  1. +++ b/src/Entity/LoginDestination.php
    @@ -179,6 +186,13 @@ class LoginDestination extends ConfigEntityBase implements LoginDestinationInter
    +   * @inheritdoc
    

    Should be {@inheritdoc}

  2. +++ b/src/Entity/LoginDestination.php
    @@ -179,6 +186,13 @@ class LoginDestination extends ConfigEntityBase implements LoginDestinationInter
    +  ¶
    

    Extra whitespace that should be removed.

  3. +++ b/src/Form/LoginDestinationRuleForm.php
    @@ -122,6 +123,17 @@ class LoginDestinationRuleForm extends EntityForm {
    +    foreach(\Drupal::languageManager()->getLanguages() as $key => $value){
    
    +++ b/src/LoginDestinationManager.php
    @@ -120,6 +120,12 @@ class LoginDestinationManager implements LoginDestinationManagerInterface {
    +      if ($destination_language != '' && $destination_language != $lang_code ){
    

    On space is needed after closing parenthesis. 1 space after 'foreach' keyword needed.

  4. +++ b/src/Form/LoginDestinationRuleForm.php
    @@ -146,7 +158,6 @@ class LoginDestinationRuleForm extends EntityForm {
    -
    

    Removement of this line seems to not be necessary.

megachriz’s picture

+++ b/src/Controller/LoginDestinationListBuilder.php
@@ -67,6 +68,9 @@ class LoginDestinationListBuilder extends DraggableListBuilder {
+      '#markup' => $entity->getLanguage() != "" ? $entity->getLanguage() : $this->t("All languages"),

+++ b/src/Form/LoginDestinationRuleForm.php
@@ -122,6 +123,17 @@ class LoginDestinationRuleForm extends EntityForm {
+    $languages[''] = $this->t("All languages");

For consistency, use single quotes here (double quotes should only be used to avoid escaping the string).

alienzed’s picture

StatusFileSize
new6.59 KB

Trying to resolve coding standards issues. With regards to update hooks, I am totally unfamiliar with how those work, but if the idea is to make sure that the language does not break existing installs, defaulting it to '' (empty string) should in theory make it backwards compatible.

rsvelko’s picture

regarding the update hooks:
- these are functions that do procedures like cleaning the cache, or changing (altering) drupal's DB schema (fields, tables) - most patches don't need to migrate/alter data/db fields structure but some do. A common trick indeed is when adding a new config to have good default like NULL, '', false, that will keep things working retro-actively.

- in general your logic seems right, that having a good default namely empty string "", should work ok. But I need to check a few things and then we'll be sure. Thing 1 to check is: how your patch works on an already installed module and 2. I need to go through the code reading it slowly and trying to figure out the implications.

@MegaChriz: thanks for the coding standards work and I'd like to ask you this:
Do you have an idea if adding
+ language:
+ type: string
+ label: 'Language'

to config/schema/login_destination.schema.yml would mean we need an update hook?

I hope you know enough about the D8 api to answer that.

megachriz’s picture

@rsvelko
I don't know if adding config keys require update hooks in D8. I haven't done much with update hooks in D8 yet. So that would need to be investigated. I know the Webform module added lots of update hooks (and probably also new config keys?).

rsvelko’s picture

ok, more and more I'm leaning towards that if the new config vars have sane defaults, that should cover all existing installs.
We just need to be carefull when checking the variable value and treat null, not defined vars / keys properly, as well as empty strings.

alienzed’s picture

If this:

/**
   * The login destination language.
   *
   * @var string
   */
  public $language = '';

is in fact supplying the default value, all should be well. There is one thing I was too lazy to implement, in the list of destinations, I just re-use the language code instead of fetching the language's name. I figured it wasn't worth querying the LanguageManager just to display the language name instead of language code, but then I suppose performance of that specific page is probably not an issue and a much longer list of enabled languages may make the language code less user friendly. Thoughts?
Either way, assuming this patch has no negative side effects, I wouldn't delay a commit.

rsvelko’s picture

1.
> $language = '' is in fact supplying the default value, all should be well.
= I agree

2. lang codes instead of names in LD rules list - I like lang codes there as they are short.

3. I've tried the patch, tested with one-time login links + language filter/rule/condition - works. Tested login trigger + language - works (tried 2 langauges and 2 destination pages - so lang 1 -> page 1, lang 2 -> page 2).

No regressions, works well on existing site w/o need for update hook.

I'm committing this one now. Will be part of release 8.x-alpha2.

  • rsvelko committed 37bdc33 on 8.x-1.x authored by alienzed
    Issue #3038968 by alienzed, rsvelko, MegaChriz: Language Aware...
rsvelko’s picture

Assigned: Unassigned » rsvelko
Category: Support request » Feature request
Status: Active » Fixed
rsvelko’s picture

Component: User interface » Code
alienzed’s picture

Sweet, thank you for the assistance getting this in :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.