I want to propose an integration with the context module, which permit to connect conditions (eg. path is user/*) with reaction (eg. set a menu item for active handler)
This could be useful in ds layouts with blocks that need contestualization but either for conditional layouts.

Thanks in advance.

#4 ds_context.patch516 bytesmuka
#4 ds_context.zip2.99 KBmuka


swentel’s picture

Status:Active» Postponed (maintainer needs more info)

Always interested ! :)

netsensei’s picture

I did something similar for Views already: http://drupal.org/project/vcd

It's a cool feature, but I would suggest waiting for a unified context API in D8. Currently, there are different options: context, rules,... each with their own dependencies. If anything, if you hook context, you might as well support rules too if you want to leave people a choice.

muka’s picture

Thank you, this is a good example. I'll study a bit more your module.

muka’s picture

Status:Postponed (maintainer needs more info)» Needs work
new2.99 KB
new516 bytes

I'm back!
Attached a proposal for a ds_context module (many thanks to netsensei for the hint).

Actually offer both a condition and a reaction called "Display suite: fields visibility".
- The reaction hide/shows the field based on conditions.
- The condition set a "default state" for selected fields (in this case the above reaction should be chosen) eg. set some fields always hidden

In this way a field can be always hidden with the exception of another condition "overriding" the default eg.
show some fields only in this menu trail.

swentel’s picture

Also, I think it might be better to use hook_entity_view_alter - or the field_attach_view_alter - that way *all* fields could benefit from the context and there's no patch needed for ds.module itself, because at this point, I think the only thing context can work on are ds fields and not field api fields, right ?

muka’s picture

Actually the reaction get entities with entity_get_info() and list the fields in entity->bundle->layout->settings.
The field api items are missing... still needs work :) I'll try to fix them soon.

I post some additional ideas:
- ds code support (condition/reaction)
- passing arguments to field (eg. block views) from a view result or ds code (as reaction)
- custom theming / layout switcher (reaction)
- hide / show a layout region

Use cases:
- node has term, display related nodes with term
- user has this role, display a layout-[$user->rid] layout
- user is going to buy a product, show the region with the related products he could be interested (based on cart or tracker as nid view arguments).

swentel’s picture

I wonder if this shouldn't be a separate project for a few reasons:

  1. I rarely use context to add full support on the issue queue of DS itself.
  2. If we start with context, I imagine rules will come along as well soon too, as netsensei suggests, which I don't use a lot as well, so again something I don't have a lot of time to support full on the issue queue.
  3. I've had this situation before where I included support for modules that I didn't even know off and could'nt help people in the issue queue if they had problems with them.

So I think I'd rather see someone else taking this up as a separate project on d.o so I can concentrate on DS core (+ contrib support that I/we at work use a lot). Muka, You are absolutely free to start such a project and maintain it yourself if you like :) Let me know what you think, because I'm pretty close to setting this one to won't fix for the reasons outlined above.

muka’s picture

Yes, make sense. This is a related module and won't help a lot on the growing of ds core.
Let's close it. Thanks

swentel’s picture

Status:Needs work» Closed (won't fix)

I've taken this to http://groups.drupal.org/node/167684 for further discussion.

yannickoo’s picture

Status:Closed (won't fix)» Active

I showed swentel that changing the view mode is possible via hook_entity_view_alter. For example when you want to force all entities to use the teaser view mode you just would write:

function mymodule_entity_view_alter(&$build, $type) {
  $build['#view_mode'] = 'teaser';

So to implement the context integration we need some hooks, let's take a look at the context.api.php file.
Also a good example is the nd_context_bm module. It has a plugins directory where the condition and the reaction is and the hook stuff is located in the nd_context_bm.module.

I think the necessary hooks are:

I will take a look at this later.

swentel’s picture

Status:Active» Closed (won't fix)

drupal.org/project/ds_context will be available soon :)

dman’s picture

Bump? We are looking for ds_context today. Is it still sandboxed?

Looks like it shouldn't be TOO hard (if x then use this alternative view mode to render the node) but if there is prior art, I'd like to go from there.
Searching not working for me yet.

attiks’s picture

Status:Closed (won't fix)» Active

@yannickoo do you already have some code?

yannickoo’s picture

I'm so sorry, I deleted that module for 1 month when cleaning my machine. This has nothing to do with Display Suite because it is for entities which are independent from Display Suite.

When I have some time I will try to recreate a context_view_mode module, okay?

attiks’s picture

#14 no problem, it looks interesting so I was just wondering. Take your time ;-)

yannickoo’s picture

FYI still have this on my todo list!

jpstrikesback’s picture

Yannicko FTW!!!

yannickoo’s picture

I thought that we create a new module which allows you to change the view mode of an entity via Context but the problem is that you might have lots of entities on a page, which entity should be changed now?

FYI I created a sandbox where I will put the code in.

phildu’s picture

the repository is empty ?

yannickoo’s picture

I have this on my machine. I need more information about the features as I described in #18.

swentel’s picture

Status:Active» Closed (won't fix)

The sandbox is there, work can go on there https://drupal.org/sandbox/yan_nick/1995902

j3ll3nl’s picture

if you got a lot of entities on a page then it is managed by a view oid?

It should only work for the viewing of a single entity. Otherwise a view could manage the view mode and the context module.