I chain Views and Entity view modes together and use features in my workflow to put things online in production. It would be very helpfull if I can add the different view modes as components to my feature. Will this be supported in the future?

Comments

keesee’s picture

Title: Exportable view modes » Features Module Support

This would be a great addition! plus one. great work on this mod. Easy and simple to use, without the overhead of DS.

beanluc’s picture

Status: Active » Needs review

This is already possible.

To capture your custom view modes in your Feature, select the Strongarm component, find the "entity view modes" variable, and check the box to include it in your Feature.

You also must capture the field settings in your content-types (or whatever entity you're using a custom Entity View Mode for) into your Feature, which I'm sure you're doing anyway.

joachim’s picture

Unfortunately, that means you can only export ALL view modes into one feature.

joachim’s picture

Status: Needs review » Active

Correct status.

gagarine’s picture

An export creating the real code like http://mearra.com/blogs/juha-niemi/drupal-7-custom-node-view-modes would be very nice.

gagarine’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
zkday’s picture

All views mode is config in module entity_view_modes we had stored in variables table with key: entity_view_modes

function entity_view_mode_entity_info_alter(&$info) {
  foreach (variable_get('entity_view_modes', array()) as $entity_type => $view_modes) {
    if (isset($info[$entity_type]['view modes'])) {
      $info[$entity_type]['view modes'] += $view_modes;
    }
  }
}

We are using module strongarm for this features. ;)

joachim’s picture

See comment #3 though.

It would be much better to have one table row per view mode and so export then one by one.

matglas86’s picture

I agree. This makes it possible to select what view modes to export and have better support for changes. The main thing for me in features is making it possible to track configuration changes.

matglas86’s picture

-- edited, duplicated my message :) sorry --

matglas86’s picture

Status: Active » Needs review

I wrote a module in a sandbox that makes a feature component per view mode. It build in such a way that it can be ported to the entity view module easily. Please checkout my sandbox here http://drupal.org/sandbox/matglas86/1818428. Its a full working example.

matglas86’s picture

StatusFileSize
new4.59 KB

Here is also a patch for the module.

I have created a sandbox to work on this feature here http://drupal.org/project/1831384

joachim’s picture

I'm not entirely sure, but is this keeping the huge monster variable this module uses and then extracting/merging back in the bits from it for Features?

matglas86’s picture

Yes it does. I implemented it in such a way that it keeps the original value in place.

Anonymous’s picture

I wanted to ask if this is possible with ctools exportables instead of features, so I poked around and concluded that it's not possible. Ctools exportables are built around database tables and their schema info. #8 is suggesting that we add a new table for view modes, and I don't know if that's essential.

The next idea would have been to generate an implementation of hook_entity_info_alter (as suggested in #5), but this presumes that the feature module has no other implementation of the same hook, so it wouldn't always fit into the workflow people are looking for.

I think Features support is the only way to do this. I haven't tested this patch yet, but I will soon.

joachim’s picture

> Ctools exportables are built around database tables and their schema info. #8 is suggesting that we add a new table for view modes, and I don't know if that's essential.

It's not essential, but it would be nice, as it would allow for #1702530: Store view modes in an entity_view_mode table (compatible with Display Suite?). And it would make Features support much much simpler!

matglas86’s picture

Well features support isnt that hard. Its not using ctools but that is. The advantage might be that code changes in ctools don't effect our code here. But that just minor. One way of exporting for everything is nice though.

How can does the implementation of ctools and tables make it more compatible with Display Suite? Can someone explain that?

lpalgarvio’s picture

i think it makes all sense to move the view modes from a variable to a {entity_view_mode} table.

this will allow entity_view_mode to be used by other modules easly, which adds visibility in the community
and also permit individual view mode exportation, which adds flexibility

might add, Entity View Modes makes a perfect companion for Panelizer =)

------------------------
i think we should also push this as much as possible into D8 Core.
we already have Views and Entity Translation UI moving in, so it only makes sense to add this as well

mark as major?

edit:
actually, see this ^_^
#1043198: Convert view modes to ConfigEntity

Anonymous’s picture

I think the case has been made to use a table. This will avoid a dependency on Features and instead will use ctools optionally.

Will someone take this on?

matglas86’s picture

I agree. I do want to say that dependency to Features is no neccesaty. It only a additional that works together when requested.

dwatts3624’s picture

I've implemented the patch in #12. On a few different test platforms the feature comes in as overridden and these values aren't recognized until I revert the feature. Once that's done everything works great!

On another note, I would also agree that hook_entity_info_alter() seems cleaner.

dave reid’s picture

Isn't there a way to tell features how to output our exportable? If so, can't we tell it to output hook_entity_info_alter() in the way we need?

dave reid’s picture

StatusFileSize
new3.68 KB

It would be great if we could use a forward-looking hook for features exports of view modes, so I'm wondering if we should have #1900676: Add specfic hooks for defining entity view modes (backport from D8) land, and then review the following patch.

dave reid’s picture

StatusFileSize
new4.65 KB
Anonymous’s picture

Status: Needs review » Needs work
@@ -115,7 +115,7 @@ function entity_view_mode_save($entity_type, $view_mode) {
   // Save the view mode.
   $view_modes = variable_get('entity_view_modes', array());
   unset($view_modes[$entity_type][$existing_view_mode]);
-  $view_modes[$entity_type][$view_mode_name] = array_intersect_key($view_mode, drupal_map_assoc(array('label', 'custom settings')));
+  $view_modes[$entity_type][$view_mode_name] = __entity_view_mode_sanitize($view_mode);
   $view_modes[$entity_type][$view_mode_name] += array('custom settings' => TRUE);
   variable_set('entity_view_modes', $view_modes);

The __ is a typo that causes a fatal error when exporting view modes.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new4.8 KB

Thanks, patch with correction.

dave reid’s picture

StatusFileSize
new5.04 KB

Re-rolled for 7.x-1.x.

dave reid’s picture

StatusFileSize
new5.07 KB

Re-rolled for 7.x-1.x. Fixed that hook_features_revert() should delete the item from the variable rather than re-save it.

dave reid’s picture

Any feedback on #28? I am very tentative to commit it without any kind of testing from someone other than myself so it may have to wait until the next release.

ramper’s picture

I can confirm that the patch in #28 is working, My set up is perhaps simple: I have three custom view modes which I tested with some image and video file display settings. The view modes exported as a feature module are listed as "In code". This is my first successful attempt at exporting entity view modes, so thank you very much!

danielphenry’s picture

Patch #28 seems to work for export but my exported view mode always appears as overridden. Honestly I think this should still be put into the module. The core of the functionality works. You can apply this patch and create a new case for this overridden issue.

To reproduce my issue: Create a coupe custom view modes. Export one of them in a feature. Enable the feature and revert it. The feature always appears as overridden and the diff displays the previous value was false while the current value is the exported view mode.

jamsilver’s picture

Status: Needs review » Needs work

Hmm, I don't think the workflow in this patch is quite right. Basically it looks in the 'entity_view_modes' variable to see which view modes are available for export:

+++ b/entity_view_mode.features.incundefined
@@ -0,0 +1,121 @@
+
+  $view_modes = variable_get('entity_view_modes', array());

But, when I enable the feature on a fresh website, the view modes it defines are declared in a default hook, are listed as "In code" in the entity view modes UI, cannot be edited in the UI and never make it into the 'entity_view_modes' variable. As such once an entity view mode is exported into a feature and 'properly reverted' (i.e. removed from the DB), it cannot be chosen again in the Features UI.

With every other features exportable config in Drupal the following workflow is possible:

1. Export a piece of config into a feature
2. Copy the feature to a fresh site, enable it - creates the piece of config
3. (Still on the fresh site) Make a further modification to the piece of config, Recreate the feature to 'update' the export code.

Indeed many people use that workflow generally while site building to keep config in code, for moving around between staging/live sites or passing to different developers in the same team.

At the moment, when I create a feature the first time & move it to a fresh install and recreate the feature again, Features loses all track of it actually being in the feature - i.e. the features[entity_view_mode] entry is removed from the .info file. In fact, at the moment I think the only reason that my feature still contains the hook_entity_view_mode_info() implementation after being Recreated is 'by accident'; if I had some other piece of config in my feature which also exported to the 'FEATURENAME.entity.inc' file, then Features would explicitly overwrite that file when recreating the module and the hook_entity_view_mode_info() implementation would disappear.

Perhaps the answer is to put a special flag 'features_export' => TRUE inside each features export? Then when listing components for features, list everything from the entity_view_modes variable and all default entity_view_modes which have that flag on it?

damienmckenna’s picture

@jamsilver: The current stable version of Strongarm stores the data in the variables table rather than loading it via hooks, are you sure you're using Strongarm v2?

jamsilver’s picture

@DamienMcKenna: Since I'm testing the patch in #28 I'm not exporting the entity view modes with Strongarm at all, but rather with the functionality that the patch adds :-).

joachim’s picture

I'm sorry to say this when a lot of work has been done on this patch, but I really don't think it's useful without #1702530: Store view modes in an entity_view_mode table (compatible with Display Suite?).

My reasoning is this: best practice with Features tends to be grouping parts of site functionality into different features. So suppose you have a site with a news page and an events calendar. You would probably want one feature for each of those, providing the node type, the fields, the views, and so on.

But when you have, say a 'front page news scroll' view mode for your news nodes, and a 'calendar pop-up' view mode for your event nodes, and you want to export them, you run into trouble: having a single variable for all the view modes means you can't split them up over several features.

danielphenry’s picture

Joachim,

I both agree and disagree with you here. Features would be much more useful to entity_view_modes if they were able to be exported separately. However I believe this patch is a step in the right direction. And until the case you mentioned is added this patch should still be good to apply. It wil force future patches to support features including when entity_view_modes are moved into tables. I think both patches need to continue to progress and whichever goes in first the other patch can adjust to meet it.

nortmas’s picture

Issue summary: View changes
StatusFileSize
new52.36 KB

I have a problem, If a view mode is in a feature but not in a DB, the diff module shows that your feature is overridden. The difference in a view mode.

Here is what it shows:

screen

I tried to revert it via Drush and from interface, nothing helped.

dobe’s picture

Agree with #35, lets get #1702530. In, while this feature is important. Schema will completely change what is exported within a feature (likely allowing more granularity). Besides #1702530 looks pretty straight forward and should be close to getting it passing automated tests.

frob’s picture

dobe’s picture

#1702530 was updated and is now passing testing. Please test!

denix’s picture

Hi, sorry but I have been looking at #1702530 and the new structure is almost ready. Did somebody already had a look at the possible changes?

z3cka’s picture

Patch from #28 work for me; many thanks!

frob’s picture

Status: Postponed » Active
joseph.olstad’s picture

Status: Active » Needs review
StatusFileSize
new1.8 KB

to be able to cleanly apply the patch from #1702530 and still use the patch #28 above, simply do this:
git clone entity_view_mode
then : apply this patch from #28
then apply this interdiff
then apply patch 54 from #1702530

I am not sure if this works yet or not, haven't yet tested.

see next comment instead

joseph.olstad’s picture

Status: Needs review » Needs work
StatusFileSize
new1.97 KB

new interdiff.
to be able to cleanly apply the patch from #1702530: Store view modes in an entity_view_mode table (compatible with Display Suite?)
AND still use the patch #28 above, follow these steps:
Step 1) git clone entity_view_mode OR cd sites/all/modules/entity_view_mode
Step 2) apply this patch from #28 (EXAMPLE: patch -p1 < example.patch)
Step 3) apply this interdiff (patch)
Step 4) apply patch 54 from #1702530

I've tested this, while it allows capturing of very basic things, the features_revert is actually doing a delete instead of a rebuild. So you can capture something (limited so far) but you cannot revert it.

needs work

joseph.olstad’s picture

Status: Needs work » Active

prior to either of these patches, features using strongarm can capture the File_entity display settings.
if we apply #1702530 then strongarm won't work anymore however that is what this issue is about, making a features export. the patches listed in #45 are a start but is a work in progress.

frob’s picture

Status: Active » Needs work

This needs an issue summary update.

If I remember correctly the goal is to allow users to add view modes from this module to features and not have to rely on strong arm. Currently #1702530: Store view modes in an entity_view_mode table (compatible with Display Suite?) is a dependency of this as it changes the way the view modes are stored. So this issue should tackle adding featurability back to this module.

denix’s picture

now that #1702530: Store view modes in an entity_view_mode table (compatible with Display Suite?) is reviewed and tested, can we hope to see a rc2 with these two developments?