Commit d75787df authored by webchick's avatar webchick

Issue #2087995 by amateescu: All entity post*() and pre*() methods should call...

Issue #2087995 by amateescu: All entity post*() and pre*() methods should call their parent implementation.
parent 1f9a488b
......@@ -242,6 +242,8 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
$this->clearBlockCacheDefinitions();
$storage_controller->deleteCategories(array($this->id() => $this));
}
......@@ -250,6 +252,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = FALSE) {
parent::postSave($storage_controller, $update);
if (!empty($this->categories)) {
$storage_controller->saveCategories($this, $this->categories);
}
......
......@@ -136,6 +136,8 @@ public function label($langcode = NULL) {
* {@inheritdoc}
*/
public function postCreate(EntityStorageControllerInterface $storage_controller) {
parent::postCreate($storage_controller);
if (!isset($this->timestamp->value)) {
$this->timestamp->value = REQUEST_TIME;
}
......@@ -145,6 +147,8 @@ public function postCreate(EntityStorageControllerInterface $storage_controller)
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
$storage_controller->saveCategories($this);
}
......@@ -152,6 +156,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::preDelete($storage_controller, $entities);
$storage_controller->deleteCategories($entities);
}
......@@ -207,4 +213,5 @@ public static function baseFieldDefinitions($entity_type) {
);
return $fields;
}
}
......@@ -191,6 +191,8 @@ public function uri() {
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
// Before saving the custom block, set changed time.
$this->changed->value = REQUEST_TIME;
}
......@@ -199,6 +201,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
// Invalidate the block cache to update custom block-based derivatives.
\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
}
......@@ -214,6 +218,8 @@ public function getInstances() {
* {@inheritdoc}
*/
public function preSaveRevision(EntityStorageControllerInterface $storage_controller, \stdClass $record) {
parent::preSaveRevision($storage_controller, $record);
if ($this->isNewRevision()) {
// When inserting either a new custom block or a new custom_block
// revision, $entity->log must be set because {block_custom_revision}.log
......
......@@ -94,6 +94,8 @@ public function uri() {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
if (!$update) {
entity_invoke_bundle_hook('create', 'custom_block', $this->id());
custom_block_add_body_field($this->id);
......@@ -107,8 +109,11 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
foreach ($entities as $entity) {
entity_invoke_bundle_hook('delete', 'custom_block', $entity->id());
}
}
}
......@@ -168,6 +168,8 @@ public function getExportProperties() {
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
$this->set('settings', $this->getPlugin()->getConfiguration());
}
......
......@@ -208,6 +208,8 @@ public function id() {
* {@inheritdoc}
*/
public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
if (empty($values['node_type']) && !empty($values['nid'])) {
$node = node_load(is_object($values['nid']) ? $values['nid']->value : $values['nid']);
$values['node_type'] = 'comment_node_' . $node->getType();
......@@ -218,6 +220,8 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
global $user;
if (!isset($this->status->value)) {
......@@ -307,6 +311,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
$this->releaseThreadLock();
// Update the {node_comment_statistics} table prior to executing the hook.
$storage_controller->updateNodeStatistics($this->nid->target_id);
......@@ -329,6 +335,8 @@ protected function releaseThreadLock() {
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
$child_cids = $storage_controller->getChildCids($entities);
entity_delete_multiple('comment', $child_cids);
......@@ -341,7 +349,6 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
* {@inheritdoc}
*/
public function permalink() {
$url['path'] = 'node/' . $this->nid->value;
$url['options'] = array('fragment' => 'comment-' . $this->id());
......
......@@ -88,6 +88,8 @@ class Category extends ConfigEntityBase implements CategoryInterface {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
if (!$update) {
entity_invoke_bundle_hook('create', 'contact_message', $this->id());
}
......@@ -100,6 +102,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
foreach ($entities as $entity) {
entity_invoke_bundle_hook('delete', 'contact_message', $entity->id());
}
......
......@@ -178,6 +178,8 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
$this->timestamp = REQUEST_TIME;
$this->setSize(filesize($this->getFileUri()));
if (!isset($this->langcode->value)) {
......@@ -193,6 +195,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::preDelete($storage_controller, $entities);
foreach ($entities as $entity) {
// Delete all remaining references to this file.
$file_usage = file_usage()->listUsage($entity);
......
......@@ -205,6 +205,8 @@ public function uri() {
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
$this->name = trim($this->label());
// @todo Do not save disabled filters whose properties are identical to
......@@ -224,6 +226,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
// Clear the static caches of filter_formats() and others.
filter_formats_reset();
......
......@@ -99,6 +99,8 @@ public function id() {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
if ($update) {
if (!empty($this->original) && $this->id() !== $this->original->id()) {
// The old image style name needs flushing after a rename.
......@@ -117,6 +119,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
foreach ($entities as $style) {
// Flush cached media for the deleted style.
$style->flush();
......
......@@ -390,6 +390,8 @@ public function offsetUnset($offset) {
* {@inheritdoc}
*/
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::preDelete($storage_controller, $entities);
// Nothing to do if we don't want to reparent children.
if ($storage_controller->getPreventReparenting()) {
return;
......@@ -411,6 +413,8 @@ public static function preDelete(EntityStorageControllerInterface $storage_contr
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
$affected_menus = array();
// Update the has_children status of the parent.
foreach ($entities as $entity) {
......@@ -434,6 +438,8 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
// This is the easiest way to handle the unique internal path '<front>',
// since a path marked as external does not need to match a router path.
$this->external = (url_is_external($this->link_path) || $this->link_path == '<front>') ? 1 : 0;
......@@ -506,6 +512,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
// Check the has_children status of the parent.
$storage_controller->updateParentalStatus($this);
......
......@@ -79,6 +79,8 @@ public function getRevisionId() {
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
// Before saving the node, set changed and revision times.
$this->changed->value = REQUEST_TIME;
}
......@@ -87,6 +89,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function preSaveRevision(EntityStorageControllerInterface $storage_controller, \stdClass $record) {
parent::preSaveRevision($storage_controller, $record);
if ($this->newRevision) {
// When inserting either a new node or a new node revision, $node->log
// must be set because {node_field_revision}.log is a text column and
......@@ -113,6 +117,8 @@ public function preSaveRevision(EntityStorageControllerInterface $storage_contro
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
// Update the node access table for this node, but only if it is the
// default revision. There's no need to delete existing records if the node
// is new.
......@@ -125,6 +131,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::preDelete($storage_controller, $entities);
if (module_exists('search')) {
foreach ($entities as $entity) {
search_reindex($entity->nid->value, 'node');
......
......@@ -171,6 +171,8 @@ public function isLocked() {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
if (!$update) {
// Clear the node type cache, so the new type appears.
\Drupal::cache()->deleteTags(array('node_types' => TRUE));
......@@ -209,6 +211,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
// Clear the node type cache to reflect the removal.
$storage_controller->resetCache(array_keys($entities));
foreach ($entities as $entity) {
......
......@@ -87,6 +87,8 @@ public function uri() {
* {@inheritdoc}
*/
public function postCreate(EntityStorageControllerInterface $storage_controller) {
parent::postCreate($storage_controller);
// Generate menu-compatible set name.
if (!$this->getOriginalID()) {
// Save a new shortcut set with links copied from the user's default set.
......@@ -111,6 +113,8 @@ public function postCreate(EntityStorageControllerInterface $storage_controller)
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
// Just store the UUIDs.
foreach ($this->links as $uuid => $link) {
$this->links[$uuid] = $uuid;
......@@ -121,6 +125,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
foreach ($this->links as $uuid) {
if ($menu_link = entity_load_by_uuid('menu_link', $uuid)) {
// Do not specifically associate these links with the shortcut module,
......@@ -137,11 +143,13 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::preDelete($storage_controller, $entities);
foreach ($entities as $entity) {
$storage_controller->deleteAssignedShortcutSets($entity);
// Next, delete the menu links for this set.
menu_delete_links('shortcut-' . $entity->id());
}
}
}
......@@ -178,10 +178,12 @@ public function getExportProperties() {
return $properties;
}
/**
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
$plugin = $this->getPlugin();
// If this plugin has any configuration, ensure that it is set.
if ($plugin instanceof ConfigurablePluginInterface) {
......
......@@ -167,6 +167,8 @@ public function isLocked() {
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
if ($this->hasLocales()) {
$config_factory = \Drupal::service('config.factory');
$properties = $this->getExportProperties();
......@@ -186,6 +188,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
// Clean up the localized entry if required.
if (\Drupal::moduleHandler()->moduleExists('language')) {
$languages = language_list();
......
......@@ -148,6 +148,8 @@ protected function init() {
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
// See if any of the term's children are about to be become orphans.
$orphans = array();
foreach (array_keys($entities) as $tid) {
......@@ -177,6 +179,8 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
// Before saving the term, set changed time.
$this->changed->value = REQUEST_TIME;
}
......@@ -185,6 +189,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::preSave($storage_controller, $update);
// Only change the parents if a value is set, keep the existing values if
// not.
if (isset($this->parent->value)) {
......
......@@ -113,6 +113,8 @@ public function uri() {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
if (!$update) {
entity_invoke_bundle_hook('create', 'taxonomy_term', $this->id());
}
......@@ -144,6 +146,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::preDelete($storage_controller, $entities);
// Only load terms without a parent, child terms will get deleted too.
entity_delete_multiple('taxonomy_term', $storage_controller->getToplevelTids(array_keys($entities)));
}
......@@ -152,6 +156,8 @@ public static function preDelete(EntityStorageControllerInterface $storage_contr
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
$vocabularies = array();
foreach ($entities as $vocabulary) {
$vocabularies[$vocabulary->id()] = $vocabulary->id();
......
......@@ -124,6 +124,8 @@ public function revokePermission($permission) {
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
if (!isset($this->weight) && ($roles = $storage_controller->loadMultiple())) {
// Set a role weight to make this new role last.
$max = array_reduce($roles, function($max, $role) {
......@@ -137,6 +139,9 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
$storage_controller->deleteRoleReferences(array_keys($entities));
}
}
......@@ -61,6 +61,8 @@ public function id() {
* {@inheritdoc}
*/
static function preCreate(EntityStorageControllerInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
if (!isset($values['created'])) {
$values['created'] = REQUEST_TIME;
}
......@@ -72,6 +74,8 @@ static function preCreate(EntityStorageControllerInterface $storage_controller,
* {@inheritdoc}
*/
public function preSave(EntityStorageControllerInterface $storage_controller) {
parent::preSave($storage_controller);
// Update the user password if it has changed.
if ($this->isNew() || ($this->pass->value && $this->pass->value != $this->original->pass->value)) {
// Allow alternate password hashing schemes.
......@@ -102,6 +106,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
if ($update) {
// If the password has been changed, delete all open sessions for the
// user and recreate the current one.
......@@ -142,6 +148,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
$uids = array_keys($entities);
\Drupal::service('user.data')->delete(NULL, $uids);
$storage_controller->deleteUserRoles($uids);
......
......@@ -291,6 +291,8 @@ public function getExportProperties() {
* {@inheritdoc}
*/
public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
parent::postSave($storage_controller, $update);
views_invalidate_cache();
}
......@@ -298,6 +300,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
* {@inheritdoc}
*/
public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
// If there is no information about displays available add at least the
// default display.
$values += array(
......@@ -317,6 +321,8 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
* {@inheritdoc}
*/
public function postCreate(EntityStorageControllerInterface $storage_controller) {
parent::postCreate($storage_controller);
$this->mergeDefaultDisplaysOptions();
}
......@@ -324,6 +330,8 @@ public function postCreate(EntityStorageControllerInterface $storage_controller)
* {@inheritdoc}
*/
public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
parent::postDelete($storage_controller, $entities);
$tempstore = \Drupal::service('user.tempstore')->get('views');
foreach ($entities as $entity) {
$tempstore->delete($entity->id());
......
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