See meta-issue: #2511554: [meta] Move some parts of Page Manager into CTools

Per #2511568: Create "context stack" service where available contexts can be registered a context stack is going to be added to CTools. Once it's in, we should use that and remove these classes:

  • Drupal\page_manager\EventSubscriber\CurrentUserContext
  • Drupal\page_manager\EventSubscriber\RouteParamContext
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dsnopek’s picture

dsnopek’s picture

I have a feeling we could use the core "lazy context" thing at this point to eliminate these classes from Page Manager. Of course, the Ctools context stack is still a good idea, but killing this code is really the goal of this issue.

tim.plunkett’s picture

Title: Remove EventSubscribers to add context to pages and use CTools "context stack" » Switch from EventSubscribers to core-style ContextProviders
Assigned: Unassigned » tim.plunkett
Status: Postponed » Active

Working on this.

tim.plunkett’s picture

Status: Active » Needs review
FileSize
49.43 KB

Unfortunately we have to duplicate ALL of LazyContextRepository just to pass along a parameter.

Status: Needs review » Needs work

The last submitted patch, 4: 2511596-pm-4.patch, failed testing.

tim.plunkett’s picture

Priority: Normal » Major
Status: Needs work » Needs review
FileSize
50.37 KB
2.49 KB
tim.plunkett’s picture

FileSize
63.86 KB
30.2 KB

Didn't have enough test coverage, static contexts didn't work.

tim.plunkett’s picture

FileSize
69.82 KB

Status: Needs review » Needs work

The last submitted patch, 8: 2511596-pm-8.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
69.86 KB
8.5 KB
tim.plunkett’s picture

+++ b/src/Context/PageContextRepository.php
@@ -0,0 +1,165 @@
+class PageContextRepository extends LazyContextRepository implements PageContextRepositoryInterface {

This is the worst class I've ever written.

dsnopek’s picture

This ... is not how I thought this would go. :-) Would it make more sense to keep the thing we had before, but allow it to also use the core context providers, so we could at least remove the duplicated ones? Or actually, that seems to be more-or-less what this doing, we just can't reuse the core route one. Hrm. This comment is full of nothing useful. :-/

neclimdul’s picture

+++ b/page_manager.services.yml
@@ -1,14 +1,20 @@
+  # Missing argument is purposeful, see \Drupal\page_manager\ContextProvidersPass.
+  page_manager.context_repository:
+    class: Drupal\page_manager\Context\PageContextRepository
+    arguments: ['@service_container']
+

Trivial to the scope of this patch but I personally prefer providing the empty array and documenting where its populated rather then leaving it missing. Makes things more clear when reading the services file what you'd expect on the other side.

arguments: ['@service_container', []]

The compiler pass can also pull in the argument and merge it so it would work if someone where to write their own compiler pass and wanted to run first for what ever reason.

Edit: remove dreditor weirdness.

Berdir’s picture

Will try to review this asap. I think it's going in the same direction as what I wrote about in #2511568: Create "context stack" service where available contexts can be registered. I need to look at this more closely, but some of the things I'm thinking about there that this probably doesn't cover yet:

* Do it in ctools, based on a generic interface
* Support multiple objects like a page manage page with their own context, by using that object as static cache instead of a property. Page manager itself already has that I think, with the page and the variant, although one is a superset of the other.
* Also take care of static contexts and relationships, in some way

andypost’s picture

Status: Needs review » Needs work

Patch seriously outdated after contexts moved to ctools

DamienMcKenna’s picture

andypost’s picture

Patch needs work cos accepted #2633052: Page variant by current language