-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
There was a problem hiding this 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
modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.module
Outdated
Show resolved
Hide resolved
modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.module
Outdated
Show resolved
Hide resolved
...oe_whitelabel_multilingual/templates/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
...oe_whitelabel_multilingual/templates/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
...oe_whitelabel_multilingual/templates/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
...oe_whitelabel_multilingual/templates/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
...oe_whitelabel_multilingual/templates/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
5623683
to
c6e37b8
Compare
There was a problem hiding this 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;
modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.module
Outdated
Show resolved
Hide resolved
modules/oe_whitelabel_multilingual/oe_whitelabel_multilingual.module
Outdated
Show resolved
Hide resolved
templates/overrides/navigation/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
templates/overrides/navigation/links--oe-multilingual-content-language-block.html.twig
Outdated
Show resolved
Hide resolved
8d71975
to
49a11c4
Compare
...whitelabel_multilingual/config/optional/block.block.openeuropa_content_language_switcher.yml
Outdated
Show resolved
Hide resolved
...s/oe_whitelabel_multilingual/config/optional/block.block.oe_whitelabel_main_page_content.yml
Outdated
Show resolved
Hide resolved
...whitelabel_multilingual/config/optional/block.block.openeuropa_content_language_switcher.yml
Outdated
Show resolved
Hide resolved
…eparate block from bottom text.
…gual on block theming.
I have some general feedback about UX for the design in BCL.
Not a blocker for this PR. |
There was a problem hiding this 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.
templates/overrides/navigation/links--oe-multilingual-content-language-block.html.twig
Show resolved
Hide resolved
templates/overrides/navigation/links--oe-multilingual-content-language-block.html.twig
Show resolved
Hide resolved
templates/overrides/navigation/links--oe-multilingual-content-language-block.html.twig
Show resolved
Hide resolved
_id, _message and _expandable are overwritten. | ||
@todo Call include once BCL 0.20 is available. | ||
#} | ||
{% set _id = "dropdown-languages" %} |
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
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.
templates/overrides/navigation/links--oe-multilingual-content-language-block.html.twig
Show resolved
Hide resolved
// Add the current language to the list. | ||
$multilingual_helper = \Drupal::service('oe_multilingual.helper'); | ||
$entity = $multilingual_helper->getEntityFromCurrentRoute(); | ||
/** @var \Drupal\Core\Entity\EntityInterface $translation */ |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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']], | ||
], | ||
]; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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])
?
There was a problem hiding this 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.
No description provided.