I can't get contextual view modes to display any view mode other than the "default" view mode.

Clean 7.51 install -> Display Suite -> Context -> Contextual View Modes

Create DS view mode: Desktop
Create Context: desktop
- Condition -> Node type: basic page
- Reaction -> View Mode: basic page -> Desktop

I've spent several hours trying to figure this out and stepped backwards trying to see if anything else points out to being the cause, however with only using DS, Context and Contextual View Modes, I can't get any of the other view modes to work. I couldn't get it to work on stable, so I moved to latest dev with no results.

I must note, this is happening with "Contextual View Modes Nodes" disabled. If I enable that sub module and point both the context and view mode to Desktop within the respective node, it uses the view mode properly. Granular only isn't exactly ideal though.

Any ideas? Maybe I'm missing something? As far as I can tell, it should be extremely straight forward to override all of the view modes globally.

Comments

philsward created an issue. See original summary.

philsward’s picture

Title: Not respecting panelizer view modes » Not using ANY view modes except default

Fixed title after digging into the problem and narrowing the issue. I originally thought it was related to panelizer but realized the problem happens before panelizer enters the equation.

philsward’s picture

philsward’s picture

Issue summary: View changes
philsward’s picture

From what I can tell, CVM is not firing properly on Node Type. All other reactions work as expected from what I can tell. I added some block reactions, menu reactions etc and they all work as expected when using the node type condition. View modes reaction is the only one that is wonky. I also found that if I add an additional condition along with node type, I can get the view mode to work. However, it only works if "require all conditions" is unchecked.

As a control, I tried using path as the only condition and view modes worked properly. As soon as you add Node Type as a second condition and require that all conditions must pass, the view mode will always go back to using the "default" view mode.

philsward’s picture

Title: Not using ANY view modes except default » CVM does not work with Node Type condition

Updated title to better reflect the nature of the issue.

philsward’s picture

I had my programmer look at this issue and he came up with a solution. Here's his comments:

The contextual_view_modes_entity_view_mode_alter() function in the contextual_view_modes.module file executes only some of the conditions when it calls
module_invoke_all('context_page_condition');

These are conditions related to the page build, and I need the "node type" condition that is not executed by this call.

By adding the following line, the node type condition will also work with the contextual_view_modes reaction:
context_node_condition($context['entity'], 'view');

This is found in the file: contextual_view_modes.module for the function starting at line 31.

Specifically, change:

function contextual_view_modes_entity_view_mode_alter(&$view_mode, $context) {

  // Some contexts have yet to fire as this hook is before the context.
  // Theme related stuff is an example.
  // Lets try to fire them. But only once.
  $static = &drupal_static(__FUNCTION__, FALSE);
  if (!$static) {
    module_invoke_all('context_page_condition');
    $static = TRUE;
  }

  // Get some more information about the entity we are looking at.
...
...
...

to

function contextual_view_modes_entity_view_mode_alter(&$view_mode, $context) {

  // Some contexts have yet to fire as this hook is before the context.
  // Theme related stuff is an example.
  // Lets try to fire them. But only once.
  $static = &drupal_static(__FUNCTION__, FALSE);
  if (!$static) {
    module_invoke_all('context_page_condition');
  // Also fire node conditions if this is a node entity
    if ($context['entity_type'] == 'node') {
      context_node_condition($context['entity'], 'view');
    }
    $static = TRUE;
  }

Adding context_node_condition($context['entity'], 'view'); to line 39

amaisano’s picture

Noticed the same thing - very frustrating. This was a problem on 2.x as well. Your tweaks make it work.

amaisano’s picture

Priority: Normal » Critical

sherakama’s picture

Thanks for the bump.

I have added the node_context call if there is an entity condition available. It should be on the 3.x dev branch for you shortly.

sherakama’s picture

Status: Active » Fixed
amaisano’s picture

Great stuff @sherakama, thanks.

Status: Fixed » Closed (fixed)

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