Working solution

Finding this solution was quite a nightmare. But, here it is.

This assumes you have a working setup of Panels in Drupal 7 already.

  1. Use a group path prefix. Set up pathauto to include your group's path as a prefix for group content. This is a challenge by itself due to various bugs and changes in Drupal, but here is my solution.
  2. Edit the node template panel page. In the CTools page manager (at /admin/structure/pages), enable the node_view (node template) page, if not already done, and then edit it (at /admin/structure/pages/edit/node_view).
  3. Create a new Panel variant.
  4. Create a selection rule by path. Click "Selection rules" in teh left sidebar for your new Panel variant. Then select from the list "String: URL path", add it, and configure it to use your group's path prefix with a wildcard, like groupname/*.
  5. Reorder your variant. Click "Reorder variants" at the top right (should be /admin/structure/pages/nojs/operation/node_view/actions/rearrange). Reorder the variants to make yours come after "Node panelizer" and before "Fallback panel". Drupal will work through the vriants and select the first where teh selection rules match, so placing it after "Fallback" would make it never show up.
  6. Test. Go to some non-panelized group content that has your group's path prefix, and see if the panel variant gets applied. To see an effect, you will have to add content to the panel variant of course.

Alternative solutions

The following solution should also work:

Panelize display modes, set display mode per group. This is a combination of the following:

  • ds_extras: needed to create additional view modes for content types
  • context: for general context management, needed by context_og
  • context_og: needed in context to detect when a node belongs to a certain group
  • contextual_view_modes: to set a view mode for a content type based on its context
  • panelizer: to panelize a view mode

You would define a context for each group for which you want a default panel, triggered by a node belonging to the group. Then you would configure the content types (with the options added by contextual_view_modes) to set a specific view mode for each of these contexts, which you created via ds_extras. And use Panels (or rather Panelizer I think) to create default panels for these new view modes.

This solution is semantic, since it is not dependent on URL patterns. However, it is also more complex, clutters the view modes namespace, and requires one new panel for each content type / view mode combination, rather than just one in the node template.

Non-working solutions

The following solutions that I tried did not work:

Selecting a Panel variant by group membership. This should work – see my instructions here. But currently (2014-09) it does not due to Drupal issue #2242511 "How to create panel variant with selection rule for groups audience field". There is an impractical workaround available, but "somebody" should go in there and fix it for real …

Using og_panels. This would be the most comfortable variant, as it avoids also the need to be admin to change a group's default layout. However, there is no Drupal 7 port of the og_panels module. See: Drupal issue #990918.

Selecting panel variants via contexts. Proposal: Create a solution from a combination of the following:

  • context: for general context management, needed by context_og. See:
  • context_og: to detect when a node belongs to a certain group. See:
  • panels: to set a panel variant in the Panels selection rules, based on the context detected via context_og. See:

Problem: Panelizer does not list the context / context_og contexts in the list of contexts of the "Context exists" selection rule. This is because these are simply two different things called "context": the Panels module does not even depend on the context module, nor vice versa.

The "Context exists" selection rule will list the "Panels contexts" that are defined in the context section above the selection rules section, if and only if that context field contains data. See this wording in the "Context exists" selection rule: "Check to see if the context exists (contains data) or does not exist (contains no data).", and the reproduction instructions from Drupal issue #1263896. This means that in effect, "context" in Panels means the same as "contextual filters" in views: it is a way to pass in arguments that can be grabbed by the view resp. the content elements on the panel, and using them in "Context exists" is rather a side use.

Using context_panels_layouts. Proposal: Create a solution from a combination of the following:

  • context: for general context management, needed by context_og
  • context_og: to set a conext when a node is part of a certain group
  • context_panels_layout: to set a panel as a context reaction
  • panels: to set a panel variant in the Panels selection rules, based on the context detected via context_og

Problem: This does not work, as context_panels_layout can only be used to set Panels layouts, not actual panel variants that also include the content added to the layout.

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>