function _update_8003_field_create_field

Creates a field by writing directly to configuration.

Upgrades using this function need to use hook_update_dependencies() to ensure they get executed after field_update_8003().

Parameters

array $field_config: An array of field properties.

Related topics

2 calls to _update_8003_field_create_field()
block_update_8008 in drupal/core/modules/block/block.install
Migrate {block_custom}.body and {block_custom}.format to block_body field.
user_update_8011 in drupal/core/modules/user/user.install
Create user picture field.

File

drupal/core/modules/field/field.install, line 22
Install, update, and uninstall functions for the Field module.

Code

function _update_8003_field_create_field(array &$field_config) {
  $uuid = new Uuid();

  // Merge in default values.
  $field_config += array(
    'uuid' => $uuid
      ->generate(),
    'entity_types' => array(),
    'cardinality' => 1,
    'translatable' => FALSE,
    'locked' => FALSE,
    'settings' => array(),
    'indexes' => array(),
    'active' => TRUE,
    'status' => 1,
    'langcode' => 'und',
  );

  // Set the storage.
  $field_config['storage'] = array(
    'type' => 'field_sql_storage',
    'module' => 'field_sql_storage',
    'active' => TRUE,
    'settings' => array(),
  );

  // Save in config.
  Drupal::config('field.field.' . $field_config['id'])
    ->setData($field_config)
    ->save();

  // Create storage for the field. This requires a field entity, but cannot use
  // the regular entity_create() function here.
  $field_entity = new Field($field_config);
  field_sql_storage_field_storage_create_field($field_entity);
}