diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 3870a62..d49f5cd 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -102,8 +102,12 @@ function entity_get_bundles($entity_type = NULL) { */ function entity_invoke_bundle_hook($hook, $entity_type, $bundle, $bundle_new = NULL) { entity_info_cache_clear(); - $method = 'handleBundle' . ucfirst($hook); + + // Notify the entity storage controller. + $method = 'onBundle' . ucfirst($hook); Drupal::entityManager()->getStorageController($entity_type)->$method($bundle, $bundle_new); + + // Invoke hook_entity_bundle_*() hooks. Drupal::moduleHandler()->invokeAll('entity_bundle_' . $hook, array($entity_type, $bundle, $bundle_new)); } diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 4d79f5d..2713085 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -236,7 +236,7 @@ public function deleteRevision($revision_id) { ->condition($this->revisionKey, $revision->getRevisionId()) ->execute(); $this->invokeFieldMethod('deleteRevision', $revision); - $this->fieldRevisionDelete($revision); + $this->deleteFieldItemsRevision($revision); $this->invokeHook('revision_delete', $revision); } } @@ -351,7 +351,7 @@ protected function buildQuery($ids, $revision_id = FALSE) { protected function attachLoad(&$queried_entities, $load_revision = FALSE) { // Attach field values. if ($this->entityInfo['fieldable']) { - $this->fieldLoad($queried_entities, $load_revision ? FIELD_LOAD_REVISION : FIELD_LOAD_CURRENT); + $this->loadFieldItems($queried_entities, $load_revision ? FIELD_LOAD_REVISION : FIELD_LOAD_CURRENT); } // Call hook_entity_load(). @@ -425,7 +425,7 @@ public function delete(array $entities) { $entity_class::postDelete($this, $entities); foreach ($entities as $entity) { $this->invokeFieldMethod('delete', $entity); - $this->fieldDelete($entity); + $this->deleteFieldItems($entity); $this->invokeHook('delete', $entity); } // Ignore slave server temporarily. @@ -468,7 +468,7 @@ public function save(EntityInterface $entity) { $this->resetCache(array($entity->id())); $entity->postSave($this, TRUE); $this->invokeFieldMethod('update', $entity); - $this->fieldSave($entity, TRUE); + $this->saveFieldItems($entity, TRUE); $this->invokeHook('update', $entity); } else { @@ -482,7 +482,7 @@ public function save(EntityInterface $entity) { $entity->enforceIsNew(FALSE); $entity->postSave($this, FALSE); $this->invokeFieldMethod('insert', $entity); - $this->fieldSave($entity, FALSE); + $this->saveFieldItems($entity, FALSE); $this->invokeHook('insert', $entity); } @@ -557,7 +557,7 @@ public function getQueryServiceName() { /** * {@inheritdoc} */ - protected function doFieldLoad($entities, $age) { + protected function doLoadFieldItems($entities, $age) { $load_current = $age == FIELD_LOAD_CURRENT; // Collect entities ids and bundles. @@ -615,7 +615,7 @@ protected function doFieldLoad($entities, $age) { /** * {@inheritdoc} */ - protected function doFieldSave(EntityInterface $entity, $update) { + protected function doSaveFieldItems(EntityInterface $entity, $update) { $vid = $entity->getRevisionId(); $id = $entity->id(); $bundle = $entity->bundle(); @@ -708,7 +708,7 @@ protected function doFieldSave(EntityInterface $entity, $update) { /** * {@inheritdoc} */ - protected function doFieldDelete(EntityInterface $entity) { + protected function doDeleteFieldItems(EntityInterface $entity) { foreach ($this->fieldInfo->getBundleInstances($entity->entityType(), $entity->bundle()) as $instance) { $field = $instance->getField(); $table_name = static::_fieldTableName($field); @@ -725,7 +725,7 @@ protected function doFieldDelete(EntityInterface $entity) { /** * {@inheritdoc} */ - protected function doFieldRevisionDelete(EntityInterface $entity) { + protected function doDeleteFieldItemsRevision(EntityInterface $entity) { $vid = $entity->getRevisionId(); if (isset($vid)) { foreach ($this->fieldInfo->getBundleInstances($entity->entityType(), $entity->bundle()) as $instance) { @@ -741,7 +741,7 @@ protected function doFieldRevisionDelete(EntityInterface $entity) { /** * {@inheritdoc} */ - public function handleFieldCreate(FieldInterface $field) { + public function onFieldCreate(FieldInterface $field) { $schema = $this->_fieldSqlSchema($field); foreach ($schema as $name => $table) { $this->database->schema()->createTable($name, $table); @@ -751,7 +751,9 @@ public function handleFieldCreate(FieldInterface $field) { /** * {@inheritdoc} */ - public function handleFieldUpdate(FieldInterface $field, FieldInterface $original) { + public function onFieldUpdate(FieldInterface $field) { + $original = $field->original; + if (!$field->hasData()) { // There is no data. Re-create the tables completely. @@ -836,7 +838,7 @@ public function handleFieldUpdate(FieldInterface $field, FieldInterface $origina /** * {@inheritdoc} */ - public function handleFieldDelete(FieldInterface $field) { + public function onFieldDelete(FieldInterface $field) { // Mark all data associated with the field for deletion. $field['deleted'] = FALSE; $table = static::_fieldTableName($field); @@ -857,7 +859,7 @@ public function handleFieldDelete(FieldInterface $field) { /** * {@inheritdoc} */ - public function handleInstanceDelete(FieldInstanceInterface $instance) { + public function onInstanceDelete(FieldInstanceInterface $instance) { $field = $instance->getField(); $table_name = static::_fieldTableName($field); $revision_name = static::_fieldRevisionTableName($field); @@ -874,7 +876,7 @@ public function handleInstanceDelete(FieldInstanceInterface $instance) { /** * {@inheritdoc} */ - public function handleBundleRename($bundle, $bundle_new) { + public function onBundleRename($bundle, $bundle_new) { // We need to account for deleted or inactive fields and instances. $instances = field_read_instances(array('entity_type' => $this->entityType, 'bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); foreach ($instances as $instance) { @@ -897,9 +899,10 @@ public function handleBundleRename($bundle, $bundle_new) { /** * {@inheritdoc} */ - protected function fieldLoadPurgedValues(EntityInterface $entity, FieldInstanceInterface $instance) { + protected function readFieldItemsToPurge(EntityInterface $entity, FieldInstanceInterface $instance) { $field = $instance->getField(); - $query = $this->database->select(static::_fieldTableName($field), 't', array('fetch' => \PDO::FETCH_ASSOC)) + $table_name = static::_fieldTableName($field); + $query = $this->database->select($table_name, 't', array('fetch' => \PDO::FETCH_ASSOC)) ->condition('entity_id', $entity->id()) ->orderBy('delta'); foreach ($field->getColumns() as $column_name => $data) { @@ -911,7 +914,7 @@ protected function fieldLoadPurgedValues(EntityInterface $entity, FieldInstanceI /** * {@inheritdoc} */ - public function doFieldPurgeData(EntityInterface $entity, FieldInstanceInterface $instance) { + public function purgeFieldItems(EntityInterface $entity, FieldInstanceInterface $instance) { $field = $instance->getField(); $table_name = static::_fieldTableName($field); $revision_name = static::_fieldRevisionTableName($field); @@ -926,7 +929,7 @@ public function doFieldPurgeData(EntityInterface $entity, FieldInstanceInterface /** * {@inheritdoc} */ - public function handleFieldPurged(FieldInterface $field) { + public function onFieldPurge(FieldInterface $field) { $table_name = static::_fieldTableName($field); $revision_name = static::_fieldRevisionTableName($field); $this->database->schema()->dropTable($table_name); diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index 6920cb0..42ea348 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -368,7 +368,7 @@ public function save(EntityInterface $entity) { $this->resetCache(array($entity->id())); $entity->postSave($this, TRUE); $this->invokeFieldMethod('update', $entity); - $this->fieldSave($entity, TRUE); + $this->saveFieldItems($entity, TRUE); $this->invokeHook('update', $entity); if ($this->dataTable) { $this->invokeTranslationHooks($entity); @@ -391,7 +391,7 @@ public function save(EntityInterface $entity) { $entity->enforceIsNew(FALSE); $entity->postSave($this, FALSE); $this->invokeFieldMethod('insert', $entity); - $this->fieldSave($entity, FALSE); + $this->saveFieldItems($entity, FALSE); $this->invokeHook('insert', $entity); } @@ -606,7 +606,7 @@ public function delete(array $entities) { $entity_class::postDelete($this, $entities); foreach ($entities as $entity) { $this->invokeFieldMethod('delete', $entity); - $this->fieldDelete($entity); + $this->deleteFieldItems($entity); $this->invokeHook('delete', $entity); } // Ignore slave server temporarily. diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php index 8371450..970eeac 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php @@ -5,7 +5,6 @@ * Contains \Drupal\Core\Entity\FieldableEntityStorageControllerBase. */ - namespace Drupal\Core\Entity; use Drupal\field\FieldInterface; @@ -15,18 +14,22 @@ abstract class FieldableEntityStorageControllerBase extends EntityStorageControllerBase implements FieldableEntityStorageControllerInterface { /** - * Loads fields for the current revisions of a group of entities. + * Loads values of configurable fields for a group of entities. * * Loads all fields for each entity object in a group of a single entity type. * The loaded field values are added directly to the entity objects. * + * This method is a wrapper that handles the field data cache. Subclasses + * need to implement the doLoadFieldItems() method with the actual storage + * logic. + * * @param array $entities - * An array of entities for which to load fields, keyed by entity ID. + * An array of entities keyed by entity ID. * @param int $age * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or * FIELD_LOAD_REVISION to load the version indicated by each entity. */ - protected function fieldLoad($entities, $age) { + protected function loadFieldItems($entities, $age) { if (empty($entities)) { return; } @@ -70,7 +73,7 @@ protected function fieldLoad($entities, $age) { // Fetch other entities from their storage location. if ($queried_entities) { // Let the storage controller actually load the values. - $this->doFieldLoad($queried_entities, $age); + $this->doLoadFieldItems($queried_entities, $age); // Invoke the field type's prepareCache() method. foreach ($queried_entities as $entity) { @@ -93,20 +96,22 @@ protected function fieldLoad($entities, $age) { } /** - * Saves field data for an entity. + * Saves values of configurable fields for an entity. * - * It should be enough to override doFieldUpdate() instead of this method. + * This method is a wrapper that handles the field data cache. Subclasses + * need to implement the doSaveFieldItems() method with the actual storage + * logic. * * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity with fields to save. + * The entity. * @param bool $update * TRUE if the entity is being updated, FALSE if it is being inserted. */ - protected function fieldSave(EntityInterface $entity, $update = TRUE) { + protected function saveFieldItems(EntityInterface $entity, $update = TRUE) { // Ensure we are working with a BC mode entity. $entity = $entity->getBCEntity(); - $this->doFieldSave($entity, $update); + $this->doSaveFieldItems($entity, $update); if ($update) { $entity_info = $entity->entityInfo(); @@ -117,20 +122,20 @@ protected function fieldSave(EntityInterface $entity, $update = TRUE) { } /** - * Deletes field data for an existing entity. - * - * This deletes all revisions of field data for the entity. + * Deletes values of configurable fields for all revisions of an entity. * - * It should be enough to override doFieldDelete() instead of this method. + * This method is a wrapper that handles the field data cache. Subclasses + * need to implement the doDeleteFieldItems() method with the actual storage + * logic. * * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity whose field data to delete. + * The entity. */ - protected function fieldDelete(EntityInterface $entity) { + protected function deleteFieldItems(EntityInterface $entity) { // Ensure we are working with a BC mode entity. $entity = $entity->getBCEntity(); - $this->doFieldDelete($entity); + $this->doDeleteFieldItems($entity); $entity_info = $entity->entityInfo(); if ($entity_info['field_cache']) { @@ -139,117 +144,127 @@ protected function fieldDelete(EntityInterface $entity) { } /** - * Delete field data for a single revision of an existing entity. - * - * The passed $entity must have a revision ID attribute. + * Deletes values of configurable fields for a single revision of an entity. * - * It should be enough to override doFieldRevisionDelete() instead of this - * method. + * This method is a wrapper that handles the field data cache. Subclasses + * need to implement the doDeleteFieldItemsRevision() method with the actual + * storage logic. * * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity with fields to save. + * The entity. It must have a revision ID attribute. */ - protected function fieldRevisionDelete(EntityInterface $entity) { - $this->dofieldRevisionDelete($entity->getBCEntity()); + protected function deleteFieldItemsRevision(EntityInterface $entity) { + $this->doDeleteFieldItemsRevision($entity->getBCEntity()); } /** - * Load configurable fields from storage. + * Loads values of configurable fields for a group of entities. * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity. + * This is the method that holds the actual storage logic. + * + * @param array $entities + * An array of entities keyed by entity ID. + * @param int $age + * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or + * FIELD_LOAD_REVISION to load the version indicated by each entity. */ - protected function doFieldLoad($queried_entities, $age) { } + abstract protected function doLoadFieldItems($entities, $age); /** - * Insert configurable fields into storage. + * Saves values of configurable fields for an entity. + * + * This is the method that holds the actual storage logic. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. * @param bool $update * TRUE if the entity is being updated, FALSE if it is being inserted. */ - protected function doFieldSave(EntityInterface $entity, $update) { } + abstract protected function doSaveFieldItems(EntityInterface $entity, $update); /** - * Delete configurable fields from storage. + * Deletes values of configurable fields for all revisions of an entity. + * + * This is the method that holds the actual storage logic. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. */ - protected function doFieldDelete(EntityInterface $entity) { } + abstract protected function doDeleteFieldItems(EntityInterface $entity); /** - * Delete specific revision of configurable fields from storage. + * Deletes values of configurable fields for a single revision of an entity. + * + * This is the method that holds the actual storage logic. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. */ - protected function doFieldRevisionDelete(EntityInterface $entity) { } + abstract protected function doDeleteFieldItemsRevision(EntityInterface $entity); /** * {@inheritdoc} */ - public function handleFieldCreate(FieldInterface $field) { } + public function onFieldCreate(FieldInterface $field) { } /** * {@inheritdoc} */ - public function handleFieldUpdate(FieldInterface $field, FieldInterface $original) { } + public function onFieldUpdate(FieldInterface $field) { } /** * {@inheritdoc} */ - public function handleFieldDelete(FieldInterface $field) { } + public function onFieldDelete(FieldInterface $field) { } /** * {@inheritdoc} */ - public function handleInstanceCreate(FieldInstanceInterface $instance) { } + public function onInstanceCreate(FieldInstanceInterface $instance) { } /** * {@inheritdoc} */ - public function handleInstanceUpdate(FieldInstanceInterface $instance, FieldInstanceInterface $orignal) { } + public function onInstanceUpdate(FieldInstanceInterface $instance) { } /** * {@inheritdoc} */ - public function handleInstanceDelete(FieldInstanceInterface $instance) { } + public function onInstanceDelete(FieldInstanceInterface $instance) { } /** * {@inheritdoc} */ - public function handleBundleCreate($bundle) { } + public function onBundleCreate($bundle) { } /** * {@inheritdoc} */ - public function handleBundleRename($bundle, $bundle_new) { } + public function onBundleRename($bundle, $bundle_new) { } /** * {@inheritdoc} */ - public function handleBundleDelete($bundle) { } + public function onBundleDelete($bundle) { } /** * {@inheritdoc} */ - public function fieldPurgeData(EntityInterface $entity, FieldInstanceInterface $instance) { - if ($values = $this->fieldLoadPurgedValues($entity, $instance)) { + public function onFieldItemsPurge(EntityInterface $entity, FieldInstanceInterface $instance) { + if ($values = $this->readFieldItemsToPurge($entity, $instance)) { $field = $instance->getField(); $definition = _field_generate_entity_field_definition($field, $instance); $items = \Drupal::typedData()->create($definition, $values, $field->getFieldName(), $entity); $items->delete(); } - $this->doFieldPurgeData($entity, $instance); + $this->purgeFieldItems($entity, $instance); } /** * Reads values to be purged for a single field of a single entity. * * This method is called during field data purge, on fields for which - * handleFieldDelete() or handleFieldInstanceDelete() has previously run. + * onFieldDelete() or onFieldInstanceDelete() has previously run. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity. @@ -260,7 +275,7 @@ public function fieldPurgeData(EntityInterface $entity, FieldInstanceInterface $ * The field values, in their canonical array format (numerically indexed * array of items, each item being a property/value array). */ - abstract protected function fieldLoadPurgedValues(EntityInterface $entity, FieldInstanceInterface $instance); + abstract protected function readFieldItemsToPurge(EntityInterface $entity, FieldInstanceInterface $instance); /** * Removes field data from storage during purge. @@ -270,11 +285,11 @@ public function fieldPurgeData(EntityInterface $entity, FieldInstanceInterface $ * @param FieldInstanceInterface $instance * The field whose values are bing purged. */ - protected function doFieldPurgeData(EntityInterface $entity, FieldInstanceInterface $instance) { } + abstract protected function purgeFieldItems(EntityInterface $entity, FieldInstanceInterface $instance); /** * {@inheritdoc} */ - public function handleFieldPurged(FieldInterface $field) { } + public function onFieldPurge(FieldInterface $field) { } } diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerInterface.php b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerInterface.php index 8b8de91..a3dc37a 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerInterface.php @@ -5,10 +5,8 @@ * Contains \Drupal\Core\Entity\ExtensibleEntityStorageControllerInterface. */ - namespace Drupal\Core\Entity; - use Drupal\field\FieldInterface; use Drupal\field\FieldInstanceInterface; @@ -20,17 +18,15 @@ * @param \Drupal\field\FieldInterface $field * The field being created. */ - public function handleFieldCreate(FieldInterface $field); + public function onFieldCreate(FieldInterface $field); /** * Allows reaction to the update of a configurable field. * * @param \Drupal\field\FieldInterface $field * The field being updated. - * @param \Drupal\field\FieldInterface $original - * The previous state of the field. */ - public function handleFieldUpdate(FieldInterface $field, FieldInterface $original); + public function onFieldUpdate(FieldInterface $field); /** * Allows reaction to the deletion of a configurable field. @@ -41,9 +37,9 @@ public function handleFieldUpdate(FieldInterface $field, FieldInterface $origina * @param \Drupal\field\FieldInterface $field * The field being deleted. * - * @see fieldPurgeData() + * @see fieldPurgeData(onFieldItemsPurge */ - public function handleFieldDelete(FieldInterface $field); + public function onFieldDelete(FieldInterface $field); /** * Allows reaction to the creation of a configurable field instance. @@ -51,7 +47,15 @@ public function handleFieldDelete(FieldInterface $field); * @param \Drupal\field\FieldInstanceInterface $instance * The instance being created. */ - public function handleInstanceCreate(FieldInstanceInterface $instance); + public function onInstanceCreate(FieldInstanceInterface $instance); + + /** + * Allows reaction to the update of a configurable field instance. + * + * @param \Drupal\field\FieldInstanceInterface $instance + * The instance being updated. + */ + public function onInstanceUpdate(FieldInstanceInterface $instance); /** * Allows reaction to the deletion of a configurable field instance. @@ -62,9 +66,9 @@ public function handleInstanceCreate(FieldInstanceInterface $instance); * @param \Drupal\field\FieldInstanceInterface $instance * The instance being deleted. * - * @see fieldPurgeData() + * @see fieldPurgeData(onFieldItemsPurge */ - public function handleInstanceDelete(FieldInstanceInterface $instance); + public function onInstanceDelete(FieldInstanceInterface $instance); /** * Allows reaction to a bundle being created. @@ -72,7 +76,7 @@ public function handleInstanceDelete(FieldInstanceInterface $instance); * @param string $bundle * The name of the bundle created. */ - public function handleBundleCreate($bundle); + public function onBundleCreate($bundle); /** * Allows reaction to a bundle being renamed. @@ -82,7 +86,7 @@ public function handleBundleCreate($bundle); * @param string $bundle_new * The new name of the bundle. */ - public function handleBundleRename($bundle, $bundle_new); + public function onBundleRename($bundle, $bundle_new); /** * Allows reaction to a bundle being deleted. @@ -90,7 +94,7 @@ public function handleBundleRename($bundle, $bundle_new); * @param string $bundle * The name of the bundle being deleted. */ - public function handleBundleDelete($bundle); + public function onBundleDelete($bundle); /** * Purges the field data for a single field on a single entity. @@ -103,7 +107,7 @@ public function handleBundleDelete($bundle); * @param \Drupal\field\FieldInstanceInterface $instance * The deleted field instance whose data is being purged. */ - public function fieldPurgeData(EntityInterface $entity, FieldInstanceInterface $instance); + public function onFieldItemsPurge(EntityInterface $entity, FieldInstanceInterface $instance); /** * Performs final cleanup after all data on all instances has been purged. @@ -111,6 +115,6 @@ public function fieldPurgeData(EntityInterface $entity, FieldInstanceInterface $ * @param \Drupal\field\FieldInterface $instance * The field being purged. */ - public function handleFieldPurged(FieldInterface $field); + public function onFieldPurge(FieldInterface $field); } diff --git a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php index 6723759..650a216 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php @@ -64,7 +64,7 @@ public function testViewsData() { // entities have no storage. $table_name = DatabaseStorageController::_fieldTableName($this->field); $data = $this->container->get('views.views_data')->get($table_name); - $this->assertTrue(empty($data), 'The field is not exposed to Views.'); + $this->assertFalse($data, 'The field is not exposed to Views.'); } } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php b/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php index a4d86eb..7d844eb 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php @@ -9,7 +9,7 @@ use Drupal\Core\Form\ConfirmFormBase; use Drupal\field\Entity\Field; -use Drupal\field\field as FieldInfo; +use Drupal\field\Field as FieldInfo; /** * Provides a confirm form for changing translatable status on translation diff --git a/core/modules/field/field.install b/core/modules/field/field.install index 1e7fb90..f0ea11b 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -97,11 +97,17 @@ function _update_8003_field_create_instance(array $field_config, array &$instanc * Writes field data directly to SQL storage. * * @param string $entity_type + * The entity type. * @param string $bundle + * The bundle. * @param int $entity_id + * The entity ID. * @param int $revision_id - * @param int $field_name + * The entity revision ID. + * @param string $field_name + * The field name. * @param array $data + * The field values, as an array keyed by langcode, delta and property name. * * @ingroup update_api */ diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index a7b71bd..7333f97 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -125,7 +125,7 @@ function field_purge_batch($batch_size) { $ids->revision_id = $revision_id; $ids->entity_id = $entity_id; $entity = _field_create_entity_from_ids($ids); - Drupal::entityManager()->getStorageController($instance->entity_type)->fieldPurgeData($entity, $instance); + Drupal::entityManager()->getStorageController($entity_type)->onFieldItemsPurge($entity, $instance); } } else { @@ -188,7 +188,7 @@ function field_purge_field($field) { $state->set('field.field.deleted', $deleted_fields); // Notify the storage layer. - Drupal::entityManager()->getStorageController($field->entity_type)->handleFieldPurged($field); + Drupal::entityManager()->getStorageController($field->entity_type)->onFieldPurge($field); // Clear the cache. field_info_cache_clear(); diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/Field.php index 4a81d03..4a6bd11 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -7,6 +7,7 @@ namespace Drupal\field\Entity; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; use Drupal\Core\Config\Entity\ConfigEntityBase; @@ -312,9 +313,9 @@ protected function saveNew() { $this->id = $this->id(); // Field name cannot be longer than Field::NAME_MAX_LENGTH characters. We - // use drupal_strlen() because the DB layer assumes that column widths + // use Unicode::strlen() because the DB layer assumes that column widths // are given in characters rather than bytes. - if (drupal_strlen($this->name) > static::NAME_MAX_LENGTH) { + if (Unicode::strlen($this->name) > static::NAME_MAX_LENGTH) { throw new FieldException(format_string( 'Attempt to create a field with an ID longer than @max characters: %name', array( '@max' => static::NAME_MAX_LENGTH, @@ -353,7 +354,7 @@ protected function saveNew() { $this->settings += $field_type['settings']; // Notify the entity storage controller. - $entity_manager->getStorageController($this->entity_type)->handleFieldCreate($this); + $entity_manager->getStorageController($this->entity_type)->onFieldCreate($this); // Save the configuration. $result = parent::save(); @@ -401,7 +402,7 @@ protected function saveUpdated() { // Notify the storage controller. The controller can reject the definition // update as invalid by raising an exception, which stops execution before // the definition is written to config. - $entity_manager->getStorageController($this->entity_type)->handleFieldUpdate($this, $original); + $entity_manager->getStorageController($this->entity_type)->onFieldUpdate($this, $original); // Save the configuration. $result = parent::save(); @@ -431,7 +432,7 @@ public function delete() { $instance->delete(FALSE); } - \Drupal::entityManager()->getStorageController($this->entity_type)->handleFieldDelete($this); + \Drupal::entityManager()->getStorageController($this->entity_type)->onFieldDelete($this); // Delete the configuration of this field and save the field configuration // in the key_value table so we can use it later during diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php index 75eae87..4d34da4 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php @@ -407,7 +407,7 @@ protected function saveUpdated() { $this->prepareSave(); // Notify the entity storage controller. - \Drupal::entityManager()->getStorageController($this->entity_type)->handleInstanceUpdate($this, $original); + \Drupal::entityManager()->getStorageController($this->entity_type)->onInstanceUpdate($this); // Save the configuration. $result = parent::save(); @@ -450,7 +450,7 @@ public function delete($field_cleanup = TRUE) { parent::delete(); // Notify the entity storage controller. - \Drupal::entityManager()->getStorageController($this->entity_type)->handleInstanceDelete($this); + \Drupal::entityManager()->getStorageController($this->entity_type)->onInstanceDelete($this); // Clear the cache. field_cache_clear(); diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 8c66ab1..0baa951 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -185,6 +185,17 @@ function testDeleteFieldInstance() { $instance = $instances[0]; $this->assertEqual($instance['bundle'], $bundle, 'The deleted instance is for the correct bundle'); + // Check that the actual stored content did not change during delete. + $schema = DatabaseStorageController::_fieldSqlSchema($field); + $table = DatabaseStorageController::_fieldTableName($field); + $column = DatabaseStorageController::_fieldColumnName($field, 'value'); + $result = db_select($table, 't') + ->fields('t', array_keys($schema[$table]['fields'])) + ->execute(); + foreach ($result as $row) { + $this->assertEqual($this->entities[$row->entity_id]->{$field->name}->value, $row->$column); + } + // There are 0 entities of this bundle with non-deleted data. $found = $factory->get('entity_test') ->condition('type', $bundle) @@ -201,24 +212,6 @@ function testDeleteFieldInstance() { ->execute(); $this->assertEqual(count($found), 10, 'Correct number of entities found after deleting'); $this->assertFalse(array_diff($found, array_keys($this->entities))); - $this->checkFieldTableContents($field); - } - - /** - * Test that the actual stored content didn't change during delete. - * - * @param FieldInterface $field - */ - protected function checkFieldTableContents(FieldInterface $field) { - $schema = DatabaseStorageController::_fieldSqlSchema($field); - $table = DatabaseStorageController::_fieldTableName($field); - $column = DatabaseStorageController::_fieldColumnName($field, 'value'); - $result = db_select($table, 't') - ->fields('t', array_keys($schema[$table]['fields'])) - ->execute(); - foreach ($result as $row) { - $this->assertEqual($this->entities[$row->entity_id]->{$field->name}->value, $row->$column); - } } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index 5eafe4d..7ff7c9d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -97,7 +97,13 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu } /** - * Save and reload an entity. + * Saves and reloads an entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity to save. + * + * @return \Drupal\Core\Entity\EntityInterface + * The entity, freshly reloaded from storage. */ protected function entitySaveReload(EntityInterface $entity) { $entity->save(); diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index e35b80d..ca1d745 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -186,7 +186,7 @@ public function save(EntityInterface $entity) { $this->resetCache(array($entity->{$this->idKey})); $entity->postSave($this, TRUE); $this->invokeFieldMethod('update', $entity); - $this->fieldSave($entity, TRUE); + $this->saveFieldItems($entity, TRUE); $this->invokeHook('update', $entity); } else { @@ -196,7 +196,7 @@ public function save(EntityInterface $entity) { $entity->enforceIsNew(FALSE); $entity->postSave($this, FALSE); $this->invokeFieldMethod('insert', $entity); - $this->fieldSave($entity, FALSE); + $this->saveFieldItems($entity, FALSE); $this->invokeHook('insert', $entity); } } diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index 5ee19d9..2e74331 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -45,10 +45,10 @@ protected function attachLoad(&$queried_entities, $load_revision = FALSE) { } if ($load_revision) { - $this->fieldLoad($queried_entities, FIELD_LOAD_REVISION); + $this->loadFieldItems($queried_entities, FIELD_LOAD_REVISION); } else { - $this->fieldLoad($queried_entities, FIELD_LOAD_CURRENT); + $this->loadFieldItems($queried_entities, FIELD_LOAD_CURRENT); } // Besides the list of nodes, pass one additional argument to