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().
array $field_config: An array of field properties.
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);
}