1c1 < From 579cbf8d047a602a842d64f8d0abdef5358f5db7 Mon Sep 17 00:00:00 2001 --- > From 730778a47aee4d5cf7fb98617e98462b02726cca Mon Sep 17 00:00:00 2001 14c14 < .../Drupal/entity/DatabaseStorageController.php | 35 +++++++++++++------- --- > .../Drupal/entity/DatabaseStorageController.php | 37 +++++++++++++------- 15a16,18 > core/modules/field/field.api.php | 4 ++- > core/modules/field/field.attach.inc | 10 ++++-- > core/modules/file/file.field.inc | 5 ++- 16a20 > core/modules/image/image.field.inc | 4 ++- 18c22 < .../node/lib/Drupal/node/NodeStorageController.php | 29 ++++++++++------ --- > .../node/lib/Drupal/node/NodeStorageController.php | 35 ++++++++++++------ 19a24 > core/modules/node/node.module | 1 + 30c35 < core/modules/taxonomy/taxonomy.api.php | 17 +++++++--- --- > core/modules/taxonomy/taxonomy.api.php | 17 ++++++--- 34c39 < .../user/lib/Drupal/user/UserStorageController.php | 28 ++++++++-------- --- > .../user/lib/Drupal/user/UserStorageController.php | 28 +++++++------- 36c41 < 29 files changed, 155 insertions(+), 103 deletions(-) --- > 34 files changed, 178 insertions(+), 112 deletions(-) 196c201 < index 77834a1..b4299d3 100644 --- > index 8d89341..cbf1a53 100644 199c204 < @@ -410,18 +410,25 @@ class DatabaseStorageController implements EntityStorageControllerInterface { --- > @@ -414,18 +414,25 @@ class DatabaseStorageController implements EntityStorageControllerInterface { 232c237 < @@ -451,7 +458,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface { --- > @@ -455,7 +462,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface { 241c246 < @@ -462,8 +469,10 @@ class DatabaseStorageController implements EntityStorageControllerInterface { --- > @@ -466,8 +473,10 @@ class DatabaseStorageController implements EntityStorageControllerInterface { 253c258 < @@ -486,14 +495,16 @@ class DatabaseStorageController implements EntityStorageControllerInterface { --- > @@ -490,14 +499,16 @@ class DatabaseStorageController implements EntityStorageControllerInterface { 263c268,269 < $function($this->entityType, $entity); --- > - $function($this->entityType, $entity); > + $function($this->entityType, $entity, $original); 294a301,385 > diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php > index 455ecc2..b4ea605 100644 > --- a/core/modules/field/field.api.php > +++ b/core/modules/field/field.api.php > @@ -490,11 +490,13 @@ function hook_field_insert($entity_type, $entity, $field, $instance, $langcode, > * The language associated with $items. > * @param $items > * $entity->{$field['field_name']}[$langcode], or an empty array if unset. > + * @param Drupal\entity\Entity $original > + * The original entity, or NULL if the caller did not provide it. > * > * @see hook_field_insert() > * @see hook_field_delete() > */ > -function hook_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { > +function hook_field_update($entity_type, Drupal\entity\EntityInterface $entity, $field, $instance, $langcode, &$items, Drupal\entity\EntityInterface $original = NULL) { > if (variable_get('taxonomy_maintain_index_table', TRUE) && $field['storage']['type'] == 'field_sql_storage' && $entity_type == 'node') { > $first_call = &drupal_static(__FUNCTION__, array()); > > diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc > index e4b28a9..122272d 100644 > --- a/core/modules/field/field.attach.inc > +++ b/core/modules/field/field.attach.inc > @@ -5,6 +5,7 @@ > * Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'. > */ > > +use Drupal\entity\EntityInterface; > use Drupal\field\FieldValidationException; > > /** > @@ -127,6 +128,7 @@ const FIELD_STORAGE_INSERT = 'insert'; > * @param $a > * - The $form in the 'form' operation. > * - The value of $view_mode in the 'view' operation. > + * - The original entity in the 'update' operation. May be NULL. > * - Otherwise NULL. > * @param $b > * - The $form_state in the 'submit' operation. > @@ -929,11 +931,13 @@ function field_attach_insert($entity_type, $entity) { > * > * @param $entity_type > * The type of $entity; e.g. 'node' or 'user'. > - * @param $entity > + * @param EntityInterface $entity > * The entity with fields to save. > + * @param EntityInterface $original > + * The original entity. May be NULL. > */ > -function field_attach_update($entity_type, $entity) { > - _field_invoke('update', $entity_type, $entity); > +function field_attach_update($entity_type, EntityInterface $entity, EntityInterface $original = NULL) { > + _field_invoke('update', $entity_type, $entity, $original); > > list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); > > diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc > index 768ee7d..d7c2dc7 100644 > --- a/core/modules/file/file.field.inc > +++ b/core/modules/file/file.field.inc > @@ -1,5 +1,7 @@ > > +use Drupal\entity\EntityInterface; > + > /** > * @file > * Field module functionality for the File module. > @@ -241,7 +243,7 @@ function file_field_insert($entity_type, $entity, $field, $instance, $langcode, > * > * Checks for files that have been removed from the object. > */ > -function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { > +function file_field_update($entity_type, EntityInterface $entity, $field, $instance, $langcode, &$items, EntityInterface $original = NULL) { > list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); > > // On new revisions, all files are considered to be a new usage and no > @@ -260,7 +262,6 @@ function file_field_update($entity_type, $entity, $field, $instance, $langcode, > } > > // Compare the original field values with the ones that are being saved. > - $original = $entity->original; > $original_fids = array(); > if (!empty($original->{$field['field_name']}[$langcode])) { > foreach ($original->{$field['field_name']}[$langcode] as $original_item) { 333a425,445 > diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc > index 2a32c15..de30e30 100644 > --- a/core/modules/image/image.field.inc > +++ b/core/modules/image/image.field.inc > @@ -1,5 +1,7 @@ > > +use Drupal\entity\EntityInterface; > + > /** > * @file > * Implement an image field, based on the file module's file field. > @@ -243,7 +245,7 @@ function image_field_insert($entity_type, $entity, $field, $instance, $langcode, > /** > * Implements hook_field_update(). > */ > -function image_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { > +function image_field_update($entity_type, EntityInterface $entity, $field, $instance, $langcode, &$items, EntityInterface $original = NULL) { > file_field_update($entity_type, $entity, $field, $instance, $langcode, $items); > } > 348c460 < index aa52582..8c1e743 100644 --- > index 0fa7b33..6d18396 100644 387c499 < @@ -194,7 +201,7 @@ class NodeStorageController extends DatabaseStorageController { --- > @@ -197,17 +204,21 @@ class NodeStorageController extends DatabaseStorageController { 391a504 > - if ($hook == 'insert' || $hook == 'update') { 393c506 < if ($hook == 'insert' || $hook == 'update') { --- > + if ($hook == 'insert') { 396c509,515 < @@ -204,7 +211,7 @@ class NodeStorageController extends DatabaseStorageController { --- > + elseif ($hook == 'update') { > + // Core does not use $original on update, but contrib might. > + node_invoke($node, $hook, $original); > + } > else if ($hook == 'predelete') { > // 'delete' is triggered in 'predelete' is here to preserve hook ordering > // from Drupal 7. 405c524 < @@ -243,7 +250,7 @@ class NodeStorageController extends DatabaseStorageController { --- > @@ -246,7 +257,7 @@ class NodeStorageController extends DatabaseStorageController { 414c533 < @@ -259,7 +266,7 @@ class NodeStorageController extends DatabaseStorageController { --- > @@ -262,7 +273,7 @@ class NodeStorageController extends DatabaseStorageController { 454a574,585 > diff --git a/core/modules/node/node.module b/core/modules/node/node.module > index 287c5af..7b29f6c 100644 > --- a/core/modules/node/node.module > +++ b/core/modules/node/node.module > @@ -935,6 +935,7 @@ function node_hook($node, $hook) { > * A string containing the name of the hook. > * @param $a2, $a3, $a4 > * Arguments to pass on to the hook, after the $node argument. > + * - If $op = 'update': $a2 is the original node. > * > * @return > * The returned value of the invoked hook. 507c638 < index 7fb7e0b..4762385 100644 --- > index 2a429e7..2989cf7 100644 580c711 < index a104270..5e2679c 100644 --- > index f7a0e35..1ea2f1d 100644 608c739 < index b9558e5..c7715fd 100644 --- > index d43455e..214fa89 100644 619c750 < @@ -2166,7 +2167,7 @@ function system_form_user_register_form_alter(&$form, &$form_state) { --- > @@ -2223,7 +2224,7 @@ function system_form_user_register_form_alter(&$form, &$form_state) {