With #1296268: Add Preview and Teaser view modes and #1051090: Revamp file view modes: migrate media_small to teaser, media_large to full, media_preview to preview; deprecate link & original applied. As I noted in http://drupal.org/node/1296268#comment-6282102 it's impossible to export file display settings for the Image display style for the preview, teaser, and full build modes. This is because default display style configuration is implemented in hook_file_default_displays() which competes with the implementation of hook_file_default_displays from Features.

Rather than implementing these as defaults that can't be changed without using an alter hook, can these instead be setup on installation? That way they could be deleted, changed, and properly exported.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Status: Active » Needs review
FileSize
4.15 KB

Attached is a patch that gets rid of the implementation of hook_file_default_displays(). It adds a step to the install hook that creates the default display style configurations in the database instead. It also adds an update hook that moves the default configs (if they have not been overridden already) to the database.

This patch is a follow on from #1051090: Revamp file view modes: migrate media_small to teaser, media_large to full, media_preview to preview; deprecate link & original and that needs to be applied before this.

Status: Needs review » Needs work

The last submitted patch, 1702700-media-move-default-display-style-to-db.patch, failed testing.

mrfelton’s picture

Status: Needs work » Needs review

Test failed because it relies on the other patch being applied first. Setting back to needs review.

Status: Needs review » Needs work

The last submitted patch, 1702700.4-media-move-default-display-style-to-db.patch, failed testing.

mrfelton’s picture

Status: Needs work » Needs review

yes - it did fail. same reason as before.

ParisLiakos’s picture

Now that those commited #4: 1702700.4-media-move-default-display-style-to-db.patch queued for re-testing.

ParisLiakos’s picture

Applied and tested manually, display settings are transferred succesfully and i can successfully export with features.
lets see what bots say before commiting

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

adding to commit list

populist’s picture

I tested the patch in #8 and it works well to export the new image styles with features. It also properly sets the defaults using the hook_install() method.

However, there is a problem with the install hook when used in an installation profile. The problem is that media_install() sets the defaults into the database (using file_save_display) which means that any feature that featurizes these items is going to come in as overridden.

Not sure if to change this issue status, since the patch does do what it needs to do, but I think that "default" behavior here should be reworked and not set directly in hook_install(). For now, here is my workaround which just removes the defaults in my featured module:

<?php

/**
 * Implementation of hook_install
 */
function panopoly_images_install() {

  // Remove initial display settings.
  module_load_include('inc', 'file_entity', 'file_entity.file_api');
  ctools_include('export');

  $default_image_styles = array(
    'preview' => 'square_thumbnail',
    'teaser' => 'medium',
    'full' => 'large',
  );

  foreach ($default_image_styles as $view_mode => $image_style) {
    $display_name = 'image__' . $view_mode . '__file_image';
    $display = array(
      'api_version' => 1,
      'name' => $display_name,
      'status' => 1,
      'weight' => 5,
      'settings' => array('image_style' => $image_style),
      'export_type' => NULL,
    );
    ctools_export_crud_delete('file_display', (object) $display);
  }

  file_info_cache_clear();
}
ParisLiakos’s picture

Status: Reviewed & tested by the community » Fixed

i see what you are saying

but I think that "default" behavior here should be reworked and not set directly in hook_install()

any insights on how should we do this?
Please open a new issue to discuss this, i committed this

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Angry Dan’s picture

Issue summary: View changes

Please feel free to correct me if I'm wrong, but don't we have exactly the same problem in the file_entity module?

Because over there we have file_entity_file_default_displays() and that does a similar thing, no?

Angry Dan’s picture