Problem/Motivation

Page manager should allow variants selection depending on current language

Proposed resolution

Add language context to reuse language module provided condition

Remaining tasks

Add tests

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kalistos created an issue. See original summary.

andypost’s picture

Status: Active » Needs review
FileSize
2.64 KB

That should be enough

Status: Needs review » Needs work

The last submitted patch, 2: 2633052-2.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
2.64 KB
andypost’s picture

Issue summary: View changes
FileSize
31.71 KB
6.18 KB
swentel’s picture

Status: Needs review » Reviewed & tested by the community

Works fine here - RTBC for me.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/EventSubscriber/CurrentLanguageContext.php
@@ -0,0 +1,63 @@
+    $event->getPageExecutable()->addContext('language', $context);

Unfortunately we just changed PageManagerContextEvent, delete the "Executable" part.

tim.plunkett’s picture

Issue tags: +Needs tests

Also please add tests

andypost’s picture

Status: Needs work » Needs review
FileSize
714 bytes
2.69 KB

fixed patch, but looking at \Drupal\Tests\page_manager\Unit\CurrentUserContextTest no idea how to write test properly

tim.plunkett’s picture

FileSize
2.72 KB
3.07 KB

We have no mechanism to reuse core context providers yet, but why duplicate their code anyway? We could just do this.
Or make this a more generic issue to reuse all core context providers instead of waiting for #2511568: Create "context stack" service where available contexts can be registered

andypost’s picture

It would be great to have all core contexts available but please keep scope of language, cos this is a blocker for multilingual sites

+++ b/src/EventSubscriber/CurrentLanguageContext.php
@@ -0,0 +1,61 @@
+    $contexts = $this->currentLanguageContextProvider->getRuntimeContexts([]);
+    foreach ($contexts as $key => $context) {
+      $event->getPage()->addContext($key, $context);
+    }

nice idea, but there's no cache dependencies set...

tim.plunkett’s picture

Taking my suggestions to #2511596: Switch from EventSubscribers to core-style ContextProviders.
Can you explain the differences between the core CurrentLanguageContext and this one?

tim.plunkett’s picture

Status: Needs review » Needs work
Wim Leers’s picture

+++ b/src/EventSubscriber/CurrentLanguageContext.php
@@ -0,0 +1,61 @@
+ * Sets the current language as a context.

Current interface language? Content language? URL language?

i.e. \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE vs \Drupal\Core\Language\LanguageInterface::TYPE_CONTENT vs \Drupal\Core\Language\LanguageInterface::TYPE_URL

See \Drupal\Core\Cache\Context\LanguagesCacheContext which also needs to make this distinction.

fluxline’s picture

not trying to hyjak the issue, but trying to solve the issue of language and path. please let me know if i should open another issue.

using as is, the path is given for the entire page entity. if 2 variants are created based on language, and a variant is selected based on role/url/content, the path is still fixed to one the one entered for the page. could the variant set the path? it will still be an issue for menus only having 1 path regardless if there is a translation or not, but that is less wok to solve.

still new to d8 so maybe i'm missing something.

dkarso’s picture

FileSize
6.82 KB

Continued from issue#2770653 to get this change request moving.

My patch holds the context class LanguageInterfaceContext event subscriber and loads the language_interface context from the LazyContextRepository.
The patch also contains a unit test for the LanguageInterfaceContext class.

@fluxline. We set the panels page path to a node id (eg: /node/503) and the node is translatable, and the page variant condition based on language (not path). The alias of the node gets requested and the variant gets loaded based on the node. We compose a single wegpage with node content with page variant content this way.

dkarso’s picture

Status: Needs work » Needs review
dkarso’s picture

FileSize
5.17 KB

Proper patch file now. Other patch holds wrong paths.

criscom’s picture

Patch in #18 works for me. Thanks!

andypost’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

And covered with tests

japerry’s picture

Status: Reviewed & tested by the community » Needs review

hmm I'm having trouble getting this patch to show up. Applies cleanly, but is not showing up in the selection criteria. Has this been tested on recent head?

The last submitted patch, 16: issue-2633052.patch, failed testing.

sylus’s picture

This applied and worked for me correctly ^_^.

Additionally recent head is currently the stable tag 1.0-alpha4.

Possible to check again?

andypost’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
21.8 KB

patch applies cleanly and works

andypost’s picture

DamienMcKenna’s picture

  • japerry committed a7eb683 on 8.x-4.x authored by andypost
    Issue #2633052 by andypost, dkarso, tim.plunkett: Page variant by...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

I've been using this in production for a while and it works well. Because #2511596: Switch from EventSubscribers to core-style ContextProviders is fairly stalled, gonna commit this now.

Status: Fixed » Closed (fixed)

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

SKAUGHT’s picture