Build modes used to provide context integration (see #1168292: Context integration). Quoting from the OP:

It would be very handy to have the possibility to set the build mode of any node currently being viewed based on active contexts.

Obviously now we talk entities so that stuff needs to be updated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Status: Active » Needs review
FileSize
3.97 KB

The attached patch provides context integration, allowing to choose which view mode apply in a particular context. Entities whose bundle is not providing custom settings for the selected view mode are ignored.

The patch exploits the new hook_entity_view_mode_alter() from #1154382: View mode no longer can be changed, thus requiring the latest core dev.

plach’s picture

Minor PHPdoc clean-up.

joachim’s picture

I feel this is out of the stated scope of this project.

Furthermore, it's very feasible that sites would want this functionality but not define custom view modes.

plach’s picture

I read again the project description: I didn't find anything that make me think this is a won't fix. Instead I'd like to point out that Build Modes featured context integration, and the project page explicitly states that this is the successor of Build Modes.

Dave Reid’s picture

I'm a little puzzled why this module would need add such a feature though. View modes are supported by Drupal core natively and we should have the necessary APIs to list view modes without needing this module. Why can't this support just go into the Context module since it's a Drupal core feature?

Dave Reid’s picture

Status: Needs review » Postponed (maintainer needs more info)
plach’s picture

Yes, technically I think this could be part of Context itself, the main reason I'm proposing this here is that Build modes had the same feature.

kiero63’s picture

I really interest by this fonctionnality. For my case as exemple, I display houses in two differents ways, one for standard houses and the other for luxe houses. Both uses the same content type, only the display mode change. As the successor of build mode which include this fonctionnality this would be great to also have this one.

Thanks

Dave Reid’s picture

Title: Context integration » Integration with View modes (core functionality)
Project: Entity view modes » Context
Version: 7.x-1.x-dev » 7.x-3.x-dev
Status: Postponed (maintainer needs more info) » Active

Again, view modes are baked into Drupal core, and use of them does not require this module at all. This is why I still insist that it is in the Context module's best interest to add the integration there. Just because Build modes supported this in D6 doesn't mean that we should for D7. Moving to the Context issue queue.

Grayside’s picture

Status: Active » Needs review
FileSize
4.93 KB

Attached patch is based on #2, for Context.module.

Grayside’s picture

Note that hook_entity_view_mode_alter() is fired before hook_node_view(). The latter is the hook used to trigger all node-centric contexts, meaning a context that is dependent on node state will not be set at the time this hook fires. To get around it for my project I created a custom context condition that evaluates the loaded node object, which is sufficient for my purposes.

Grayside’s picture

Status: Needs review » Needs work

Extending from #11, and the comments in the API documentation, node conditions are triggered only on "full" view mode. If you have an alternate view mode, you need to manually trigger the node conditions:

/**
 * Implementation of hook_node_view().
 */
function example_node_view($node, $view_mode) {
  if ($view_mode === 'new_view_mode') {
    $object = menu_get_object();
    if (isset($object->nid) && $object->nid === $node->nid) {
      context_node_condition($node, 'view');
    }
  }
}

This is a sufficiently significant break with Context module expectations, that I think it needs a solution before this functionality is at all worthwhile.

Quick Solution

This reaction has a checkbox that indicates whatever View mode it sets should be treated as equivalent to full for purposes of context module condition evaluation.

Deep Solution

The View Modes system should have an ability to acknowledge modes other than full/default as "full page views", this configuration setting would be checked as opposed to simple the machine name of the mode.

rreiss’s picture

Issue summary: View changes

#10 doesn't work for me - Latest context version (7.x-3.2).
I'm using Path condition.

JordiTR’s picture

Hi you all.

I also think that having this natively on Context is a great idea, since we can define new views modes, but I've always wonder how to change them dinamically. The only place I know is on Views, but I always prefer use fields on Views. My impression is that being able to set different contexts for showing the same node with different view modes depending on different conditions, is the real sense on having view modes. Or told otherwise, context is logically the right way to use view modes.

For example, I can use on context a condition to detect mobile platforms and then display them with a proper view mode, meanwhile the node is displayed with a full fields display on a context for desktop screens. This is a feature I've been looking for a long time and with that reaction on Context would be a great site building technique.

In fact I also think that responding to tablets and phones, or if you prefer having a "condition" based on "breakpoints" might be core on Context, at least nowadays ;-)

Just my 2 cents. Thanks.

JordiTR’s picture

All in all, I'll try to have a test on Plach patch. Thanks!

JordiTR’s picture

FileSize
10.95 KB

Hi you all,

I see that this thread is old and not very active but I'm very interested on it. I've implemented Plach strategy on #2 but instead of patching Context I've converted it on a new module that extends Context. You can see the module attached. It installs as any other module and appears inside any context set available on the reactions list.

It's not working, as pointed on comment #13, but after many hours of studying hooks related on node view I have to admit that I don't know why and how to solve it. It would be great if someone could help, since considering that maybe it's not a good idea to extend core Context with that feature as Dave Reid defends, on the other hand for me it's clear that Context itself is a very good environment to change node view display depending on different reasons (maybe Rules could be another place but for me Context it's a core element of every Drupal project I work with).

So, if anyone is interested on having a look at the module any help would be very appreaciatted.

webmestre’s picture

Hi JordiTR,

I tried your CONTEXT_VIEW_MODES module.
I found it to be WONDERFUL !!!!! I invite to urgently commit it in the public Drupal part.

In addition with Breakpoint + Context Breakpoint modules, there's a really good tool to produce adaptative websites without coding.
Works fine with Bootstrap sub-themes.

JordiTR’s picture

Ups!, is it really working for you?

webmestre’s picture

Hi Jordi,

the release https://www.drupal.org/files/issues/context_view_modes.zip works fine for me.

philsward’s picture

I'm going to agree that this should be included with context as a core reaction. View modes are an integral part of Drupal even though they may not be out of the box. Custom modules create their own view modes and with the ability to easily create them through Display Suite or Entity View Modes, it's a step away from needing a view mode reaction in context. Since Drupal does have Full Content and Teaser available out of the box, it makes sense to insert this into contexts core to be extended by all entities.

"If" view modes were not a part of Drupal core, I would agree with the logic to leave it as a contrib module, but since view modes are a part of Drupal Core, I firmly believe context should react on them.