I'm proposing to add a filter based on the entity view_mode to the condition. This would for example serve the following use-case:

  • You want to trigger a context based on a field of node that is currently viewed (node/$nid).
  • On the same page you're showing a block that shows a list of teasers (lots of other nodes).
  • Without a filter on the view mode the context is triggered if any of the nodes displayed on this page have a matching field.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torotil’s picture

Here's a patch against 7.x-1.x. For convenience I've also made a patch against 7.x-1.1 (for sites that use stable+patches).

jhedstrom’s picture

Patch in #1 works as advertised.

azinck’s picture

Status: Needs review » Reviewed & tested by the community

#1 Works great. Thanks! Marking RTBC

mErilainen’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
FileSize
3.37 KB

I have updated the patch to work with latest dev version of the module. There was a commit which added the view mode context condition in Decemeber http://cgit.drupalcode.org/context_entity_field/commit/?id=81f9108 but this patch seems to work better. Now there are two ways to choose a "Entity view mode" condition. These should be merged into the latest dev version.

mErilainen’s picture

Status: Needs work » Needs review
FileSize
6.77 KB

Here is an updated patch. It removes the view mode plugin, because in the patched version the view mode selection is in the same entity field plugin.

In my experience this patched version works better, because it will check an entity, for example in a view, to have both the view mode AND some field value, before the context condition is met. When those two are separated, it's possible that another entity will make the other context condition pass, and another entity the other one.

Will probably need some update to tests and possible an update hook, which I'm not sure how to do. Changing to "Needs review" for testing.

Because there is a change in the info file, this can be only applied by pulling the latest version with git.

mavimo’s picture

Hi guys, thank you for the effort on this patch, my plan is to complete the testing part and release 7.x-1.1 ASAP, then integrate other patch.. sorry for delay :(

If someone is interested to help me on the test development let me know.

awolfey’s picture

#5 is working for me. Thanks.

rwohleb’s picture

I agree that the view mode filtering needs to be part of "context_condition_entity_field" instead of a separate plugin. While I could probably setup contexts in the proper AND/OR configurations I would require, it would be a pain. Integrating them makes this a LOT easier.

Here is an updated version of patch #5 that consolidates handling of settings (and default values), does some extra value filtering, and adds additional descriptive text to the new view-mode filter. It's essentially the same as that in #5, but fixes some general issues with how the settings array is handled.

The patch from #2205345-4: Latest dev doesn't respect old settings has the same handling of settings. My hope is that aligning things this way will make it easier to get these two tickets into the dev branch.

tanc’s picture

There is an issue in the patch in #8 which when composing the options array to choose the view mode the keys are overwritten by later iterations. So for example it isn't possible to choose 'Full content (Content)' as 'Full content (User)' overwrites it as they share the same key 'full'. This patch introduces the entity type prepended with a colon before the view mode machine name as the key and therefore allows all view modes to be chosen. There execute handler is modified to assemble the key from the $entity_type and the $view_name.

Otherwise the patch seems to be doing what I expect and is working nicely. Thanks!

marcelovani’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

I tested and can confirm that patch #9 works
This solution is a lot better than the current solution on the 7.x-1.x dev branch, which BTW has a bug:

The execution of entity_view_mode plugin should happen before the execution of entity_field plugin:

function context_entity_field_entity_view($entity, $type, $view_mode, $langcode) {
  if ($plugin = context_get_plugin('condition', 'entity_field')) {
    $plugin->execute($type, $entity);
  }

  if ($plugin = context_get_plugin('condition', 'entity_view_mode')) {
    $plugin->execute($type, $view_mode);
  }
}

Increasing priority to major and recommending that a new tag is created.

back-2-95’s picture

patch #37 ?

marcelovani’s picture

Sorry, #9,