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

OEL-1167: Theme the content language switcher #94

Merged
merged 36 commits into from
Mar 21, 2022
Merged

OEL-1167: Theme the content language switcher #94

merged 36 commits into from
Mar 21, 2022

Conversation

GilNovacomm
Copy link
Contributor

No description provided.

Copy link
Contributor

@drishu drishu left a comment

Choose a reason for hiding this comment

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

  • also place the block so it appears above the content;
  • replace the enabling of oe_multilingual in the runner with this module;
  • and update the branch of course

@GilNovacomm GilNovacomm force-pushed the OEL-1167 branch 2 times, most recently from 5623683 to c6e37b8 Compare March 16, 2022 16:48
Copy link
Contributor

@drishu drishu left a comment

Choose a reason for hiding this comment

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

Again:

  • also place the block so it appears above the content (to make sure of this also place the content block, see oe_theme);
  • replace the enabling of oe_multilingual in the runner with this module;

@GilNovacomm GilNovacomm force-pushed the OEL-1167 branch 3 times, most recently from 8d71975 to 49a11c4 Compare March 17, 2022 11:00
drishu
drishu previously approved these changes Mar 18, 2022
drishu
drishu previously approved these changes Mar 18, 2022
drishu
drishu previously approved these changes Mar 18, 2022
drishu
drishu previously approved these changes Mar 18, 2022
@donquixote
Copy link
Contributor

I have some general feedback about UX for the design in BCL.
This is not really the place to fix this, but I am going to mention it anyway:

  • The open/close button looks like a radio element, but it does not behave as such, defying user expectations.
  • The open/close icon always points down. It should point up when the list is opened.

Not a blocker for this PR.

Copy link
Contributor

@donquixote donquixote left a comment

Choose a reason for hiding this comment

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

I left some comments.
Maybe some of these should lead to changes, but some maybe can be ignored, if there are good reasons why we do it this way, or decisions were already made in the past.

_id, _message and _expandable are overwritten.
@todo Call include once BCL 0.20 is available.
#}
{% set _id = "dropdown-languages" %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this id unique enough?
We could use 'dropdown-content-language'.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could also use a randomized id, but this is bad for caching I think.

// Add the current language to the list.
$multilingual_helper = \Drupal::service('oe_multilingual.helper');
$entity = $multilingual_helper->getEntityFromCurrentRoute();
/** @var \Drupal\Core\Entity\EntityInterface $translation */
Copy link
Contributor

Choose a reason for hiding this comment

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

Put a @var doc on the $multilingual_helper service above, then you don't need one here.

@@ -109,7 +109,7 @@ public function testMultilingualLanguageSwitcherBlockRendering(): void {
$crawler = new Crawler($html);

// Make sure that content language switcher block is present.
$actual = $crawler->filter('#dropdown-languages');
$actual = $crawler->filter('div.collapse.mt-3');
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like to see the .mt-3 here, but I suppose we have to for disambiguation?
Worst case we have to update this test when this class changes.

@@ -57,6 +59,9 @@ function oe_whitelabel_multilingual_preprocess_links__oe_multilingual_content_la
],
];
}

// Generate required ids.
$variables['expandable_id'] = Html::getUniqueId('bcl-expandable');
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if caching (render cache) could cause the same id to be used elsewhere on the same page.
But I think this would need a very convoluted scenario, which we should ignore for the time being.
So I am ok with it.

'#attributes' => ['class' => ['me-2']],
],
];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the scenario where this happens?

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw I was considering to suggest early return pattern here (invert the if to get rid of indentation).
But then we would have to drop the early return when we add the $variables['expandable_id'].
This is why I prefer to use early return only in functions with a single responsibility - which is often not the case for preprocess.
So ok to keep it this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also if language is 'und', will the message "This page is not available in ***." make sense for all cases?

I think we should settle for something that works, we have no time to investigate all possible scenarios.
If you say you want to keep the current version, let's go with it.

$variables['languages'][] = [
'path' => $translation->toUrl()->setAbsolute(TRUE)->toString(),
'hreflang' => $translation->language()->getId(),
'label' => $languages[$translation->language()->getId()]->getName(),
Copy link
Contributor

Choose a reason for hiding this comment

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

We could introduce a local var for $translation->language()->getId(), to avoid the repeated call, e.g. $current_content_language_id.

We could also check whether $languages[$current_content_language_id] exists.
Would be strange if it does not. Perhaps if a site language is deleted, renamed or disabled, while translations still exist? I don't think it will happen.

];
// If we don't have a language id defined yet, the current translation wasn't
// saved, so we don't add it to the list.
if ($translation->language()->getId() !== 'und') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice you are using 'und' string literal instead of a constant.
In Drupal 7 I would have told you to use LANGUAGE_NONE.
Now this has changed, see LANGUAGE_NONE changed to LANGUAGE_NOT_SPECIFIED, LANGUAGE_NOT_APPLICABLE and LANGUAGE_MULTIPLE added

Not sure if we also need to support other possible values.
Perhaps safer to just check isset($languages[$current_content_language_id])?

Copy link
Contributor

@donquixote donquixote left a comment

Choose a reason for hiding this comment

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

Good enough, we might fine-tune in follow-up.

@drishu drishu changed the title OEL-1167 Multilingual submodule OEL-1167: Theme the content language switcher Mar 21, 2022
@drishu drishu merged commit 1b1df0d into 1.x Mar 21, 2022
@drishu drishu deleted the OEL-1167 branch March 21, 2022 17:26
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.

3 participants