7.x field.module field_bundle_settings($entity_type, $bundle, $settings = NULL)

Gets or sets administratively defined bundle settings.

Parameters

string $entity_type: The type of $entity; e.g., 'node' or 'user'.

string $bundle: The bundle name.

array|null $settings: (optional) The settings to store, an associative array with the following elements:

  • view_modes: An associative array keyed by view mode, with the following key/value pairs:

    • custom_settings: Boolean specifying whether the view mode uses a dedicated set of display options (TRUE), or the 'default' options (FALSE). Defaults to FALSE.
  • extra_fields: An associative array containing the form and display settings for extra fields (also known as pseudo-fields):

    • form: An associative array whose keys are the names of extra fields, and whose values are associative arrays with the following elements:

      • weight: The weight of the extra field, determining its position on an entity form.
    • display: An associative array whose keys are the names of extra fields, and whose values are associative arrays keyed by the name of view modes. This array must include an item for the 'default' view mode. Each view mode sub-array contains the following elements:

      • weight: The weight of the extra field, determining its position when an entity is viewed.
      • visible: TRUE if the extra field is visible, FALSE otherwise.

Return value

array|null If no $settings are passed, the current settings are returned.

Related topics

5 calls to field_bundle_settings()
FieldInfo::prepareExtraFields in modules/field/field.info.class.inc
Prepares 'extra fields' for the current run-time context.
FieldUpdatePathTestCase::testFilledUpgrade in modules/simpletest/tests/upgrade/update.field.test
Tests that the update is successful.
field_ui_display_overview_form_submit in modules/field_ui/field_ui.admin.inc
Form submission handler for field_ui_display_overview_form().
field_ui_field_overview_form_submit in modules/field_ui/field_ui.admin.inc
Form submission handler for field_ui_field_overview_form().
field_view_mode_settings in modules/field/field.module
Returns view mode settings in a given bundle.
2 string references to 'field_bundle_settings'
drupal-7.field.database.php in modules/simpletest/tests/upgrade/drupal-7.field.database.php
Test content for the field update path.
field_update_7002 in modules/field/field.install
Split the all-inclusive field_bundle_settings variable per bundle.

File

modules/field/field.module, line 587
Attach custom data fields to Drupal entities.

Code

function field_bundle_settings($entity_type, $bundle, $settings = NULL) {
  if (isset($settings)) {
    variable_set('field_bundle_settings_' . $entity_type . '__' . $bundle, $settings);
    field_info_cache_clear();
  }
  else {
    $settings = variable_get('field_bundle_settings_' . $entity_type . '__' . $bundle, array());
    $settings += array(
      'view_modes' => array(),
      'extra_fields' => array(),
    );
    $settings['extra_fields'] += array(
      'form' => array(),
      'display' => array(),
    );

    return $settings;
  }
}

Comments

manimejia’s picture

To set the 'visibility' of an 'extra' field using field_bundle_settings(),
use this :
$extra_field[$view_mode]['visible'] = TRUE; // or FALSE
and NOT this (as the above example suggests):
$extra_field[$view_mode]['visibility'] = 'visible';// looks like values are 'visible' or 'hidden'

See field_ui_display_overview_form_submit() for a better example.

Also reported in the Drupal documentation issue queue.

lelizondo’s picture

Here is another example to hide the "History" in the user profile page:

<?php
$settings = array(
		'extra_fields' => array(
			'display' => array(
				// One sub-array per pseudo-field in displayed entities:
				'summary' => array(
					// One sub-array per view mode for the entity type, including
					// the 'default' mode:
					'default' => array(
						'visible' => FALSE,
					),
				),
			),
		),
	);
	
	field_bundle_settings("user", "user", $settings);
?>
GrigoriuNicolae’s picture

Don't forget to add the weight key in the summary sub-array. Otherwise you risk to have the https://www.drupal.org/node/1120584 error.