I don't think we should be providing the print view mode for all entities but in the case of field collections it might make sense. That being said i think there are three areas where this could be implemented

1. Custom module
2. Print module
3. Field Collection module

Below is the relevant code so if it is decided that this is a worthwhile feature or if someone needs help it is in the record.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pirog’s picture

Here is some code to do this in a custom module

function MYMODULENAME_entity_info_alter(&$info) {
  // Add the 'Print' view mode for field_collections
  if (module_exists('field_collection')) {
    $info['field_collection_item']['view modes'] += array(
      'print' => array(
        'label' => t('Print'),
        'custom settings' => FALSE,
      ),
    );
  }
}
pirog’s picture

Status: Active » Needs review
FileSize
507 bytes

here is a patch to the latest 7.x-2.x-dev branch in case people want to do that instead

jcnventura’s picture

Status: Needs review » Fixed
jcnventura’s picture

Project: Printer, email and PDF versions » Field collection
Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Fixed » Active

One question, to fago or pirog: Considering that the 'print' view mode is part of the core book module, why is the above patch needed?

pirog’s picture

If book has a print view mode also then i guess the real question would be not why this patch implements a print view mode for field collections but why this module does so in general. The purpose of the patch was just to extend the print view mode already provided by this module beyond just node and to field collections as well. Maybe we should consider removing the print view mode from this module all together?

Here are some additional thoughts:

I am not super familiar with book... but is "print" in the book module intended to provide the same kind of use case as the one in this module, ie to determine how an entity is to be displayed for "printing"? If they provide different use cases then i think we should probably rename the one provided by this module.

If they provide the same use case then we would probably just want to have this module check to see if book is enabled and if not then provide the view mode itself?

pirog’s picture

So here is what is in both Print and Book

Print:

/**
 * Implements hook_entity_info_alter().
 */
function print_entity_info_alter(&$info) {
  // Add the 'Print' view mode for nodes.
  $info['node']['view modes'] += array(
    'print' => array(
      'label' => t('Print'),
      'custom settings' => FALSE,
    ),
  );
  // Add the 'Print' view mode for field_collections
  if (module_exists('field_collection')) {
    $info['field_collection_item']['view modes'] += array(
      'print' => array(
        'label' => t('Print'),
        'custom settings' => FALSE,
      ),
    );
  }
}

Book:

/**
 * Implements hook_entity_info_alter().
 */
function book_entity_info_alter(&$info) {
  // Add the 'Print' view mode for nodes.
  $info['node']['view modes'] += array(
    'print' => array(
      'label' => t('Print'),
      'custom settings' => FALSE,
    ),
  );
}

So if the use cases are the same would we want to just add a check to see if book is not enabled for Print's implemention? The field collection patch could then stand since it probably doesn't make a ton of sense to put it in book but ive seen crazier things... such as on the 71L bus this morning.

jcnventura’s picture

Is a check for the book necessary? I think it just overwrites it with the same info, anyway...

pirog’s picture

Yeah if there are no namespace collision issues to worry about then i am all for keeping it the way it is.

jmuzz’s picture

Issue summary: View changes
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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