Any ideas how to render a different view mode for a block in different circumstances? I didn't want to post in #1318054: Ability to select view mode per region as you marked it as won't fix. But it would still be very useful to specify a view mode when placing a block in a region. Thoughts?


indytechcook’s picture

The recommended method is to make 2 different entities and place them in the different regions. I feel this decouples the blocks from one another.

In code, you could use bean_view($bean, $view_mode). You need to pass in the Bean object which you can get from bean_load or bean_load_delta.

beanluc’s picture


The Entity View Modes contrib module provides this functionality to Bean.

brantwynn’s picture

beanluc: That module allows for one to add more view modes to the entity type, but it won't help for contextual view mode rendering.

tanc: Have you considered writing a bean plugin that does this selective view mode bit? Perhaps adding conditions that "consider" some type of context before calling bean_view($bean, $view_mode)?

indytechcook: Using two separate entities is probably the most organized solution as long as one can explain to content editors why there are sets of beans that "do the same thing" all over the site.

beanluc’s picture

it won't help for contextual view mode rendering

It's achievable with Views. Possibly Panels too, not sure, haven't tried. You can choose the view-mode of other entities displayed in a Panel.

I'm just providing alternatives, so that "duplicate the entity" isn't the only option. For some users, it will be fine. For others, it will be as distasteful and useless as duplicating nodes or terms. Just because the user-interfaces of certain presentation tools haven't yet caught up with the idea that entity functionality should be exposed for entities of any type, whether core, contrib or custom, doesn't mean that the power of the entity system is, or should be, only reserved for (let's say) nodes.

I'm not even arguing that this should be a feature in Bean. I'm convinced that Bean already does what it needs to (in combination with Entity View Modes), and, that contextual configuration is a job for another module.

Things like the DisplaySuite modules, the Omega/Delta system, and the Context module don't provide a view-mode choice yet, but they could in time. Ideally, they would work the way Views does: If the item being displayed is an entity, any entity, provide the view-mode chooser.

brantwynn’s picture to render a different view mode for a block in different circumstances?

Before bean we do not have blocks as entities, therefore, the idea of a view mode selection for blocks would be completely overlooked for a module like context or display suite.

brantwynn’s picture

Forking this idea into a new project:

brantwynn’s picture

Wow... actually kinda stumped on this. I tried a few things but I haven't committed them to the sandbox yet.

First Pass:

hook_form_FORM_ID_alter() on the context editor - a total nightmare, and doesn't solve for any logic in saving contexts. I didn't go too far with this because it seemed hack-ish.

Second Pass:

context_reaction_bean extends context_reaction_block - I got fairly far with this where I basically created a new context reaction that worked just like blocks but only dealt in Beans. This worked on some levels, but I still had to hook the context editor in some ways to get view mode involved and there was a bunch of weird crossover going on with just extending block context as a new reaction. Didn't seem feasible.

Third Pass:

Create a bean plugin that has custom fields for selecting a context and view modes. Any number of view mode/context pairs could be added. Ultimately, this still needs to override the plugin::view() method to insert the view mode somehow.

Fourth Pass:

Use form alter on the bean_form itself and do some work with a custom bean_context table and additional form_submit handler that saves context info. Ideally this would also override bean_view somehow so that one could dynamically insert a $view_mode argument into $bean->view. I haven't gotten exceptionally far with this either and running low on ideas.


beanluc’s picture

Maybe it's easier to extend DisplaySuite, rather than Context itself?

I don't know. Just a thought.

brantwynn’s picture


Let me know if this is working for you. I think you'll still need the patch that opens up 'title' property to the view mode as a field. This is a Bean that displays other beans within. Users can pick any number of beans to show inside the Context Bean. This bean will listen using get_context() to determine which view mode to use for its children. You'll need to be careful assigning criteria as there could be crossover between criteria, therefore multiple contexts loaded on one page, and therefore, the block will likely display redundant results Note: I haven't tested it outside some fairly limited use cases.

indytechcook’s picture

This is awesome work. Great potential!

Can someone summarize this issue and put a book page together? Or add to the current one?

DamienMcKenna’s picture

DamienMcKenna’s picture

Issue summary:View changes

Small type

andrewmacpherson’s picture