Skip to content

Commit

Permalink
OPENEUROPA-1754: Add metadata on page header alter hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
imanoleguskiza committed Apr 8, 2019
1 parent 67837f9 commit c8fa410
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions oe_multilingual.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
declare(strict_types = 1);

use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
Expand Down Expand Up @@ -110,13 +111,19 @@ function oe_multilingual_page_header_pre_render(array $build): array {
$multilingual_helper = \Drupal::service('oe_multilingual.helper');
$content_language_switcher_provider = \Drupal::service('oe_multilingual.content_language_switcher_provider');
$language_manager = \Drupal::languageManager();
$cache = new CacheableMetadata();
$cache->addCacheContexts(['languages:language_content']);

$entity = $multilingual_helper->getEntityFromCurrentRoute();
// Bail out if there is no entity or if it's not a content entity.
if (!$entity || !$entity instanceof ContentEntityInterface) {
$cache->applyTo($build);
return $build;
}

$cache->addCacheableDependency($entity);
$cache->applyTo($build);

// Render the links only if the current entity translation language is not
// the same as the current site language.
/** @var \Drupal\Core\Entity\EntityInterface $translation */
Expand Down
2 changes: 1 addition & 1 deletion tests/features/content-language-switcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Content language selector
| Title | Titolo pagina |
| Body | Testo pagina |

Scenario: Visitor navigating to an available translation shouldn't see the language selector
Scenario: Visitor navigating to the original content shouldn't see the language selector
When I visit the "Page title" content
Then I should see the heading "Page title"
And I should see "Page body"
Expand Down

0 comments on commit c8fa410

Please sign in to comment.