To set or get the 'visibility' of an 'extra' field using field_bundle_settings(),
the example in code says this:

      'extra_field_1' => array(
        // One sub-array per view mode for the entity type, including
        // the 'default' mode:
        'default' => array(
          'weight' => The weight of the pseudo-field,
          'visibility' => Whether the pseudo-field is visible or hidden,
        ),
        'full' => ...
      ),

But the code in field_ui_display_overview_form_submit() says this:

  // Save data for 'extra' fields.
  foreach ($form['#extra'] as $name) {
    $bundle_settings['extra_fields']['display'][$name][$view_mode] = array(
      'weight' => $form_values['fields'][$name]['weight'],
      'visible' => $form_values['fields'][$name]['type'] == 'visible',
    );
  }

The difference
is that 'visibility' is controlled by:
$view_mode['visible'] = TRUE; // or FALSE
and NOT by
$view_mode['visibility'] = 'visible';// looks like values are 'visible' or 'hidden'

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

manimejia’s picture

Title: Documentation problem with Reply to comment » Documentation problem with field_bundle_settings()
jhodgdon’s picture

Title: Documentation problem with field_bundle_settings() » field_bundle_settings() doc example is wrong

That assessment looks correct to me, but we should also check the code that uses the bundle settings and verify there.

jhodgdon’s picture

I grepped through the code, and am seeing 'visibility' being used in:
- hook_field_extra_fields_display_alter() -- sample function body
- field_info_extra_fields() docblock example (similar to the one in this issue)

Ah. _field_extra_fields_pre_render(), which actually uses the visibility information referenced here, is definitely looking for a ['visible'] component as a boolean. And I found this usage in other spots too... So I can confirm the analysis in this issue report. The 2 above spots also need to be fixed along with the spot reported in this issue.

jhodgdon’s picture

Status: Active » Needs review
FileSize
2.18 KB

Here's a patch.

jhodgdon’s picture

FileSize
2.18 KB

It might help if I could spell visible. Try this patch instead.

kim-day’s picture

The patch looks good to me. It fixes the 3 instances correctly.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Reviewed & tested by the community

RTBC as per #6. Should be applied to 8.x and 7.x.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

Patch no longer applies to 8.x or 7.x. Needs a re-roll.

Dries’s picture

Status: Needs work » Needs review

#5: 1055234-v2.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1055234-v2.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
1.21 KB

I rerolled the patch. It looks like the last instance, in field.api.php, must have been caught in another patch. Comment #3 has the summary.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks linclark! Assuming the test bot agrees and the patch applies, this should be back to RTBC. Confirmed that the third hunk from the previous patch is already at
http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x. Thanks all!

Status: Fixed » Closed (fixed)

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