When more than one context of the same type is present (e.g. entity:node), only the final context of those contexts is available for page title token replacement in Page Manager.

To reproduce:

  • Create a Panels page with Page Manager.
  • Add more than one context of the same type. The easiest way to do this in stock Drupal is to reference one Article and one Page, as they are both nodes.
  • The behavior is easiest to notice in a debugger - step through \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant::getContextAsTokenData() and observe as the value of the first node is overwritten with the second, and so on.

The end user effect here is when using the [node:title] token to set the page title, which node is referred to is unclear, and only the final node can be actually be referenced.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DragoonBoots created an issue. See original summary.

DragoonBoots’s picture

I tested this with Page Manager's Block page, and it has the same issue, likely because the problem section of code here is duplicated from that implementation. Adding as a related issue as they probably share a solution.

This appears to be trivial to fix, but I can't think of a solution that wouldn't break BC because the returned array's keys would have to change.

DamienMcKenna’s picture

Version: 8.x-3.x-dev » 8.x-4.x-dev
manuel.adan’s picture

As @Berdir mention at #2851749-3: Multiple contexts of same type - all but one ignored for page title tokens:

Token API does not support multiple entities of the same type.

There is an issue asking for such support: #1920688: Support multiple instances of the same token type in token replacement. The latest approach for that is to add a token-aliasing system. For example, to get information from the current_user context, the token would look like this:

[user{current_user}:name]

I tried the latest patch (#40) and it works for me in D8.5. Since I need it, I added support for token aliases in panels title, that obviously depends on the mentioned same-context token support in core. Marking this as postponed + blocked because of this.

Another bad behaviour I found is that currently only the latest context of the same type is set even if it is empty. So having the current_user context and another user type context (e.g., from an {user} argument), the second overrides the first even if it has no value. It is solved as well with this patch.