_field_write_instance

  1. drupal
    1. drupal7
Versionen
drupal7 _field_write_instance($instance, $update = FALSE)

Store an instance record in the field configuration database.

Übergabeparameter

$instance An instance structure.

$update Whether this is a new or existing instance.

Verwandte Themen

Code

modules/field/field.crud.inc, line 479

<?php
function _field_write_instance($instance, $update = FALSE) {
  $field = field_read_field($instance['field_name']);
  $field_type = field_info_field_types($field['type']);

  // Set defaults.
  $instance += array(
    'settings' => array(),
    'display' => array(),
    'widget' => array(),
    'required' => FALSE,
    'label' => $instance['field_name'],
    'description' => '',
    'weight' => 0,
    'deleted' => 0,
  );

  // Set default instance settings.
  $instance['settings'] += field_info_instance_settings($field['type']);

  // Set default widget and settings.
  $instance['widget'] += array(
    // TODO: what if no 'default_widget' specified ?
    'type' => $field_type['default_widget'],
    'settings' => array(),
  );
  // Check widget module.
  $widget_type = field_info_widget_types($instance['widget']['type']);
  $widget_module = $widget_type['module'];
  $widget_active = module_exists($widget_module);
  $instance['widget']['settings'] += field_info_widget_settings($instance['widget']['type']);
  $instance['widget']['module'] = $widget_module;
  $instance['widget']['active'] = $widget_active;

  // Make sure there is at least display info for the 'full' context.
  $instance['display'] += array(
    'full' => array(),
  );
  // Set default display settings for each context.
  foreach ($instance['display'] as $context => $display) {
    $instance['display'][$context] += array(
      'label' => 'above',
      'exclude' => 0,
      // TODO: what if no 'default_formatter' specified ?
      'type' => $field_type['default_formatter'],
      'settings' => array(),
    );
    $formatter_type = field_info_formatter_types($instance['display'][$context]['type']);
    // TODO : 'hidden' will raise PHP warnings.
    $instance['display'][$context]['module'] = $formatter_type['module'];
    $instance['display'][$context]['settings'] += field_info_formatter_settings($instance['display'][$context]['type']);
  }

  // The serialized 'data' column contains everything from $instance that does
  // not have its own column and is not automatically populated when the
  // instance is read.
  $data = $instance;
  unset($data['id'], $data['field_id'], $data['field_name'], $data['bundle'], $data['widget']['type'], $data['weight'], $data['deleted']);

  $record = array(
    'field_id' => $instance['field_id'],
    'field_name' => $instance['field_name'],
    'bundle' => $instance['bundle'],
    'widget_type' => $instance['widget']['type'],
    'widget_module' => $widget_module,
    'widget_active' => $widget_active,
    'weight' => $instance['weight'],
    'data' => $data,
    'deleted' => $instance['deleted'],
  );
  // We need to tell drupal_update_record() the primary keys to trigger an
  // update.
  if ($update) {
    $record['id'] = $instance['id'];
    $primary_key = array('id');
  }
  else {
    $primary_key = array();
  }
  drupal_write_record('field_config_instance', $record, $primary_key);
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen