1 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 display mode, with the following key/value pairs:

    • custom_settings: Boolean specifying whether the display 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' display mode. Each display 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

File

core/modules/field/field.module, line 852
Attach custom data fields to Backdrop entities.

Code

function field_bundle_settings($entity_type, $bundle, $settings = NULL) {
  if (isset($settings)) {
    $config = config('field.bundle.' . $entity_type . '.' . $bundle);
    $data = array(
      'bundle' => $bundle,
      'entity_type' => $entity_type,
    ) + $settings;
    $config->setData($data);
    $config->save();
    field_info_cache_clear();
  }
  else {
    $config = config('field.bundle.' . $entity_type . '.' . $bundle);
    $data = $config->get();
    if (empty($data)) {
      $settings = array();
    }
    else {
      // Remove bundle and entity type from settings, as they are already known.
      $settings = array_diff_key($data, array(
        'bundle' => $bundle,
        'entity_type' => $entity_type,
      ));
    }
    $settings += array(
      'view_modes' => array(),
      'extra_fields' => array(),
    );
    $settings['extra_fields'] += array(
      'form' => array(),
      'display' => array(),
    );

    return $settings;
  }
}