In current workflow developer is required to specify display mode type = hidden for every field he wishes not to show for new display mode. This is very tedious and prone to error because /every/ field needs to be set to hidden where only few fields wanted to be displayed for the new display mode.

this patch handles setting display mode type = hidden when no type was specified for given display mode.

@todo: Add documentation to field_create_instance mentioning that setting display type = hidden is not required and is default type.

Comments

litwol’s picture

Status: Needs review » Needs work

taking note to run diffs agains fresh cvs checkout and not local bzr checkout.

yched’s picture

Then the behavior just becomes 'nothing is displayed in new view modes until the admin explicitly configures the mode", which I don't see as better.

Right now, view modes for which nothing is configured just use the display settings for the 'full' mode, which is how this behaved in CCK D6, and is IMO what makes most sense in the current state of the UI.

This being said, the real solution would be #553298: Redesign the 'Manage Display' screen (see screenshot in #83).

litwol’s picture

StatusFileSize
new1.22 KB

When field instances are added, these values should be explicitly set. Attached patch is for DX improvement. I'll make a patch to fix UX if could point me to the right api which to make explicitly set the default display type to full.

litwol’s picture

Status: Needs work » Needs review

Sending patch for review..

litwol’s picture

StatusFileSize
new1.48 KB

I forgot i had to make them from webroot...

douggreen’s picture

This patch doesn't work for me because _field_info_prepare_instance() sets the default to full. Do we need to do that?

  // Fallback to 'full' display settings for unspecified view modes.
  $entity_info = entity_get_info($instance['object_type']);
print_r($entity_info);
  foreach ($entity_info['view modes'] as $view_mode => $info) {
    if (!isset($instance['display'][$view_mode])) {
      $instance['display'][$view_mode] = $instance['display']['full'];
    }
  }
catch’s picture

Agreed this makes things very unwieldy if defining fields and instances in code.

Every time you add a new view mode, you need to go through every single instance attached to the bundle to explicitly set it to hidden. I've added some custom code to my instance install and update hooks which sets this by default, but then the field info array is only going to get bigger and bigger. So I like the direction here of not showing a field unless it's set to show manually, but also defaulting to on for instances saved via the UI.

chx’s picture

the default should be an instance setting not something hardwired.

yched’s picture

the default should be an instance setting not something hardwired.

That's exactly what #553298: Redesign the 'Manage Display' screen does now (see #98 over there)

$instance = array(
  'field_name' => 'field_foo',
  'object_type' => 'node',
  'bundle' => 'page',
  // ...
  'display' => array(
    'default' => array(
      'label' => 'above',
      'type' => 'text_default',
    ),
    'teaser' => array(
      // ...
    ),
  ),
);
field_create_instance($instance);
catch’s picture

Status: Needs review » Closed (duplicate)

Let's mark this duplicate then. Default per instance seems like the best bet to me as well.