Incorrect context passed to ctools_context_get_context_from_relationship()

Created on 2 June 2021, over 3 years ago
Updated 1 February 2023, almost 2 years ago

Problem

In ctools_context_get_context_from_relationships() the context passed to ctools_context_get_context_from_relationship() is not always the context specified by the relationship. Instead if the relationship's context is not present, then the context passed to the relationship is whatever the variable $rcontexts was last set to in the previous loops.

As a side note, it is also curious that ctools_context_get_context_from_relationship() is always called, even though the relationship plugin specifies a required context and that required context does not exist. This side note is possibly a point of clarification rather than a bug, but what is the purpose of required context in the relationship plugin if the plugin always gets called regardless as to whether the context exists or not? Is it the responsibility of the relationship plugin to check that the context passed in is the correct type and not NULL? If so:

  • What is the correct response for a relationship plugin when the context is not the correct type or NULL? For example ctools_terms_from_node_context() relationhsip plugin does not appear to check whether the context is the correct type, it makes an assumption that $context is a node, and it returns a ctools_context_create_empty() context when $context->data is empty, which would be the case if $context was NULL.
  • If the relationship plugin returns a ctools_context_create_empty() context when $context is NULL then this alters the behaviour of views panes views_content_views_panes_content_type_render() because the context exists and is empty, rather than context not existing at all, so views arguments are determined to be an empty array rather than the default 'all' exception.

Steps to reproduce

Add two relationships with single contexts to a panels page and create a situation where only the first context exists e.g. for a node page:

  • add first relationship requiring a node context e.g. term from node
  • add second relationship requiring a context loaded by the first relationship e.g. term parent
  • load the node without adding any terms
  • you should see that the node context is incorrectly passed to the second term parent relationship

Proposed resolution

The cause appears to be this commit: https://git.drupalcode.org/project/ctools/commit/4f4c425 from issue #2399313: Relationship silently left out if it has optional required context β†’ . Previously ctools_context_get_context_from_relationship() was never called if there was no context. After this commit, it is always called even when context is NULL (missing rather than empty).

The quick fix for passing the wrong context would be to ensure $rcontext is unset/reset on each loop.

In addition, if the correct behaviour of relationship plugins is to return empty context when their required context is missing, then views pane handling of 'all' probably needs to be fixed to account for empty rather than no context.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States lwalley

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024