Commit 44d1ac57 authored by catch's avatar catch
Browse files

Issue #3262384 by manuel.adan: Assigned shortcut set is not cleaned on user removal

(cherry picked from commit 09913ad57fd360c0ec1eacc43af842f30b8c2cc9)
(cherry picked from commit c20ea2ac)
parent 45c63730
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\shortcut\Entity\ShortcutSet; use Drupal\shortcut\Entity\ShortcutSet;
...@@ -383,3 +384,11 @@ function shortcut_themes_installed($theme_list) { ...@@ -383,3 +384,11 @@ function shortcut_themes_installed($theme_list) {
} }
} }
} }
/**
* Implements hook_ENTITY_TYPE_delete().
*/
function shortcut_user_delete(EntityInterface $entity) {
// Clean up shortcut set mapping of removed user account.
\Drupal::entityTypeManager()->getStorage('shortcut_set')->unassignUser($entity);
}
...@@ -185,6 +185,20 @@ public function testShortcutSetUnassign() { ...@@ -185,6 +185,20 @@ public function testShortcutSetUnassign() {
$this->assertSame($default_set->id(), $current_set->id(), "Successfully unassigned another user's shortcut set."); $this->assertSame($default_set->id(), $current_set->id(), "Successfully unassigned another user's shortcut set.");
} }
/**
* Tests assign clearing on user removal.
*/
public function testShortcutSetUnassignOnUserRemoval() {
$new_set = $this->generateShortcutSet($this->randomMachineName());
$shortcut_set_storage = \Drupal::entityTypeManager()->getStorage('shortcut_set');
$shortcut_set_storage->assignUser($new_set, $this->shortcutUser);
$this->shortcutUser->delete();
$current_set = shortcut_current_displayed_set($this->shortcutUser);
$default_set = shortcut_default_set($this->shortcutUser);
$this->assertSame($default_set->id(), $current_set->id(), "Successfully cleared assigned shortcut set for removed user.");
}
/** /**
* Tests deleting a shortcut set. * Tests deleting a shortcut set.
*/ */
......
Supports Markdown
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