Commit a820153f authored by alexpott's avatar alexpott
Browse files

Issue #1735118 by swentel, yched, xjm, larowlan, alexpott, tim.plunkett: Convert Field API to CMI.

parent 5a6647be
......@@ -12,7 +12,7 @@
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Plugin\PluginSettingsBase;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime\DateHelper;
......
......@@ -12,7 +12,7 @@
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Plugin\PluginSettingsBase;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Datetime\DrupalDateTime;
/**
......
......@@ -48,13 +48,12 @@ function setUp() {
$this->drupalLogin($web_user);
// Create a field with settings to validate.
$this->field = array(
$this->field = field_create_field(array(
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'datetime',
'settings' => array('datetime_type' => 'date'),
);
field_create_field($this->field);
$this->instance = array(
));
$this->instance = field_create_instance(array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
......@@ -64,8 +63,7 @@ function setUp() {
'settings' => array(
'default_value' => 'blank',
),
);
field_create_instance($this->instance);
));
$this->display_options = array(
'type' => 'datetime_default',
......@@ -304,6 +302,7 @@ function testDefaultValue() {
// Set the default value to 'blank'.
$this->instance['settings']['default_value'] = 'blank';
$this->instance['default_value_function'] = 'datetime_default_value';
field_update_instance($this->instance);
// Display creation form.
......
......@@ -9,7 +9,7 @@
use Drupal\Component\Plugin\PluginBase;
use Drupal\edit\EditorInterface;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Defines a base editor (Create.js PropertyEditor widget) implementation.
......
......@@ -8,7 +8,7 @@
namespace Drupal\edit;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Defines an interface for in-place editors (Create.js PropertyEditor widgets).
......
......@@ -9,7 +9,7 @@
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Selects an in-place editor (an Editor plugin) for a field.
......
......@@ -7,7 +7,7 @@
namespace Drupal\edit;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Interface for selecting an in-place editor (an Editor plugin) for a field.
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\edit\Access\EditEntityFieldAccessCheckInterface;
......
......@@ -8,7 +8,7 @@
namespace Drupal\edit;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Interface for generating in-place editing metadata for an entity field.
......
......@@ -9,7 +9,7 @@
use Drupal\edit\EditorBase;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Defines the "direct" Create.js PropertyEditor widget.
......
......@@ -9,7 +9,7 @@
use Drupal\edit\EditorBase;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Defines the "form" Create.js PropertyEditor widget.
......
......@@ -28,7 +28,6 @@ function setUp() {
parent::setUp();
$this->installSchema('system', 'variable');
$this->installSchema('field', array('field_config', 'field_config_instance'));
$this->installSchema('entity_test', array('entity_test', 'entity_test_rev'));
// Set default storage backend.
......@@ -58,12 +57,12 @@ function setUp() {
*/
function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) {
$field = $field_name . '_field';
$this->$field = array(
$this->field = array(
'field_name' => $field_name,
'type' => $type,
'cardinality' => $cardinality,
);
$this->$field_name = field_create_field($this->$field);
$this->$field = field_create_field($this->field);
$instance = $field_name . '_instance';
$this->$instance = array(
......
......@@ -9,7 +9,7 @@
use Drupal\edit\EditorBase;
use Drupal\Component\Annotation\Plugin;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
* Defines the "wysiwyg" Create.js PropertyEditor widget.
......
......@@ -11,7 +11,7 @@
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\edit\EditorInterface;
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
/**
......
......@@ -24,12 +24,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->installSchema('field', array('field_config', 'field_config_instance'));
}
/**
* Tests basic CRUD operations on EntityDisplay objects.
*/
......
......@@ -234,6 +234,9 @@ function hook_field_info_alter(&$info) {
* indexes specified by the field-type module. Some storage engines might
* not support indexes.
* - foreign keys: (optional) An array of Schema API foreign key definitions.
* Note, however, that the field data is not necessarily stored in SQL.
* Also, the possible usage is limited, as you cannot specify another field
* as related, only existing SQL tables, such as {taxonomy_term_data}.
*/
function hook_field_schema($field) {
if ($field['type'] == 'text_long') {
......@@ -1302,7 +1305,7 @@ function hook_field_storage_details_alter(&$details, $field) {
* FIELD_LOAD_REVISION to load the version indicated by each entity.
* @param $fields
* An array listing the fields to be loaded. The keys of the array are field
* IDs, and the values of the array are the entity IDs (or revision IDs,
* UUIDs, and the values of the array are the entity IDs (or revision IDs,
* depending on the $age parameter) to add each field to.
* @param $options
* An associative array of additional options, with the following keys:
......@@ -1370,7 +1373,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
* FIELD_STORAGE_INSERT when inserting a new entity.
* @param $fields
* An array listing the fields to be written. The keys and values of the
* array are field IDs.
* array are field UUIDs.
*/
function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $op, $fields) {
$id = $entity->id();
......@@ -1464,7 +1467,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $
* The entity on which to operate.
* @param $fields
* An array listing the fields to delete. The keys and values of the
* array are field IDs.
* array are field UUIDs.
*/
function hook_field_storage_delete(\Drupal\Core\Entity\EntityInterface $entity, $fields) {
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
......@@ -1488,7 +1491,7 @@ function hook_field_storage_delete(\Drupal\Core\Entity\EntityInterface $entity,
* The entity on which to operate.
* @param $fields
* An array listing the fields to delete. The keys and values of the
* array are field IDs.
* array are field UUIDs.
*/
function hook_field_storage_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, $fields) {
$vid = $entity->getRevisionId();
......@@ -1712,13 +1715,13 @@ function hook_field_storage_delete_instance($instance) {
* FIELD_LOAD_CURRENT to load the most recent revision for all fields, or
* FIELD_LOAD_REVISION to load the version indicated by each entity.
* @param $skip_fields
* An array keyed by field IDs whose data has already been loaded and
* An array keyed by field UUIDs whose data has already been loaded and
* therefore should not be loaded again. Add a key to this array to indicate
* that your module has already loaded a field.
* @param $options
* An associative array of additional options, with the following keys:
* - field_id: The field ID that should be loaded. If unset, all fields should
* be loaded.
* - field_id: The field UUID that should be loaded. If unset, all fields
* should be loaded.
* - deleted: If TRUE, deleted fields should be loaded as well as non-deleted
* fields. If unset or FALSE, only non-deleted fields should be loaded.
*/
......@@ -1735,11 +1738,11 @@ function hook_field_storage_pre_load($entity_type, $entities, $age, &$skip_field
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity with fields to save.
* @param $skip_fields
* An array keyed by field IDs whose data has already been written and
* An array keyed by field UUIDs whose data has already been written and
* therefore should not be written again. The values associated with these
* keys are not specified.
* @return
* Saved field IDs are set set as keys in $skip_fields.
* Saved field UUIDs are set as keys in $skip_fields.
*/
function hook_field_storage_pre_insert(\Drupal\Core\Entity\EntityInterface $entity, &$skip_fields) {
if ($entity->entityType() == 'node' && $entity->status && _forum_node_check_node_type($entity)) {
......@@ -1770,11 +1773,11 @@ function hook_field_storage_pre_insert(\Drupal\Core\Entity\EntityInterface $enti
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity with fields to save.
* @param $skip_fields
* An array keyed by field IDs whose data has already been written and
* An array keyed by field UUIDs whose data has already been written and
* therefore should not be written again. The values associated with these
* keys are not specified.
* @return
* Saved field IDs are set set as keys in $skip_fields.
* Saved field UUIDs are set as keys in $skip_fields.
*/
function hook_field_storage_pre_update(\Drupal\Core\Entity\EntityInterface $entity, &$skip_fields) {
$first_call = &drupal_static(__FUNCTION__, array());
......
......@@ -1170,7 +1170,7 @@ function field_attach_insert(EntityInterface $entity) {
$storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_id = $field['uuid'];
$field_name = $field['field_name'];
if (!empty($entity->$field_name)) {
// Collect the storage backend if the field has not been written yet.
......@@ -1211,7 +1211,7 @@ function field_attach_update(EntityInterface $entity) {
$storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_id = $field['uuid'];
$field_name = $field['field_name'];
// Leave the field untouched if $entity comes with no $field_name property,
// but empty the field if it comes as a NULL value or an empty array.
......@@ -1254,7 +1254,7 @@ function field_attach_delete(EntityInterface $entity) {
$storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_id = $field['uuid'];
$storages[$field['storage']['type']][$field_id] = $field_id;
}
......@@ -1287,7 +1287,7 @@ function field_attach_delete_revision(EntityInterface $entity) {
$storages = array();
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_id = $field['uuid'];
$storages[$field['storage']['type']][$field_id] = $field_id;
}
......@@ -1531,11 +1531,16 @@ function field_entity_bundle_create($entity_type, $bundle) {
* Implements hook_entity_bundle_rename().
*/
function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
db_update('field_config_instance')
->fields(array('bundle' => $bundle_new))
->condition('entity_type', $entity_type)
->condition('bundle', $bundle_old)
->execute();
$instances = field_read_instances();
foreach ($instances as $instance) {
if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) {
$id_new = $instance['entity_type'] . '.' . $bundle_new . '.' . $instance['field_name'];
$instance->id = $id_new;
$instance->bundle = $bundle_new;
$instance->allowBundleRename();
$instance->save();
}
}
// Clear the cache.
field_cache_clear();
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
* Field Info API, providing information about available fields and field types.
*/
use Drupal\field\FieldInstance;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\field\FieldInfo;
/**
......
......@@ -3,6 +3,4 @@ description: 'Field API to add fields to entities like nodes and users.'
package: Core
version: VERSION
core: 8.x
dependencies:
- field_sql_storage
required: true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment