Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | interdiff-view-mode-filter-8-9.txt | 1.54 KB | tanc |
#9 | 2022197-view-mode-filter-9.patch | 9.92 KB | tanc |
#8 | 2022197-view-mode-filter-8.patch | 9.76 KB | rwohleb |
#5 | context_entity_field-remove_view_mode_plugin-2022197-5.patch | 6.77 KB | mErilainen |
#4 | context_entity_field-view_mode-2022197-4.patch | 3.37 KB | mErilainen |
Comments
Comment #1
torotil CreditAttribution: torotil commentedHere'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).
Comment #2
jhedstromPatch in #1 works as advertised.
Comment #3
azinck CreditAttribution: azinck commented#1 Works great. Thanks! Marking RTBC
Comment #4
mErilainen CreditAttribution: mErilainen commentedI 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.
Comment #5
mErilainen CreditAttribution: mErilainen commentedHere 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.
Comment #6
mavimo CreditAttribution: mavimo commentedHi 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.
Comment #7
awolfey CreditAttribution: awolfey commented#5 is working for me. Thanks.
Comment #8
rwohlebI 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.
Comment #9
tancThere 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!
Comment #10
marcelovaniI 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:
Increasing priority to major and recommending that a new tag is created.
Comment #11
back-2-95patch #37 ?
Comment #12
marcelovaniSorry, #9,