Once I enable the project issue module, all my features become overridden because of the introduced view mode.

This is a burden for distributions like Commons, where we try override as little as possible from the given codebase.

Is there a way to use the project issue module without having to recreate all existing features?

Comments

dww’s picture

What? features doesn't let other modules define view modes? That seems like a bug in features.

Sadly, there's no way to define view modes that are tied to only specific node types.

But ugh, this is lame.

And it just got worse via #1979066: Consider using field formatters to display changes ...

BarisW’s picture

I've fixed it by adding a hook like this:

<?php
function MYMODULE_field_default_field_instances_alter(&$instances) {
  foreach ($instances as &$instance) {
    if ($instance['entity_type'] == 'node' && $instance['bundle'] != 'project_issue') {
      $instance['display']['issuemetadata'] = array(
        'label' => 'above',
        'type' => 'hidden',
      );
    }
  }
}
?>
dww’s picture

Ahh, cool. Good to know. That probably means there's a hook_field_default_field_instances() or something. ;) thanks

BarisW’s picture

Yes that's true, there is a hook_field_default_field_instances which you can use to add fields only for specific content types.

Drupal Commons uses that a lot. For instance, I've created a feature to add a files field to given node types like this:

<?php

<?php
/**
 * @file
 * commons_files.features.field_instance.inc
 */

/**
 * Implements hook_field_default_field_instances().
 */
function commons_files_field_default_field_instances() {
  // Get a list of content types that should have the File field added.
  $commons_files_entity_types = commons_files_get_entity_types_with_files();
  if (!empty($commons_files_entity_types)) {
    foreach ($commons_files_entity_types as $entity_type => $bundles) {
      foreach (array_keys($bundles) as $bundle) {
        commons_files_field_definition($field_instances, $entity_type, $bundle);
      }
    }
  }

  // Translatables
  // Included for use with string extractors like potx.
  t('Files');

  return $field_instances;
}

/**
* Contains a field definition export for the Image Insert field for re-use
* across content types.
*/
function commons_files_field_definition(&$field_instances, $entity_type, $bundle) {
  $field_instances["$entity_type-$bundle-field_files"] = array(
    'bundle' => $bundle,
    'deleted' => '0',
    'description' => '',
    'display' => array(
      'default' => array(
        'label' => 'above',
        'module' => 'file',
        'settings' => array(),
        'type' => 'file_default',
        'weight' => '13',
      ),
      'teaser' => array(
        'label' => 'above',
        'settings' => array(),
        'type' => 'hidden',
        'weight' => 0,
      ),
    ),
    'ds_extras_field_template' => '',
    'entity_type' => $entity_type,
    'field_name' => 'field_files',
    'label' => 'Files',
    'required' => 0,
    'settings' => array(
      'description_field' => 1,
      'file_directory' => "$bundle/files",
      'file_extensions' => 'jpg jpeg gif png doc docx txt xls xlsx pdf ppt pps odt ods odp tar gz tgz zip',
      'max_filesize' => '16 MB',
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'active' => 1,
      'module' => 'file',
      'settings' => array(
        'insert' => 0,
        'insert_absolute' => 0,
        'insert_class' => '',
        'insert_default' => 'auto',
        'insert_styles' => array(
          'auto' => 'auto',
          'icon_link' => 0,
          'image' => 0,
          'image_35x35' => 0,
          'image_50x50' => 0,
          'image_50x50_avatar' => 0,
          'image_large' => 0,
          'image_medium' => 0,
          'image_rich_snippets_thumbnail' => 0,
          'image_thumbnail' => 0,
          'link' => 0,
        ),
        'insert_width' => '',
        'progress_indicator' => 'throbber',
      ),
      'type' => 'file_generic',
      'weight' => '3',
    ),
  );
}
?>