Loading core/modules/shortcut/shortcut.module +9 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\shortcut\Entity\ShortcutSet; Loading Loading @@ -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); } core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php +14 −0 Original line number Diff line number Diff line Loading @@ -185,6 +185,20 @@ public function testShortcutSetUnassign() { $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. */ Loading Loading
core/modules/shortcut/shortcut.module +9 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\shortcut\Entity\ShortcutSet; Loading Loading @@ -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); }
core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php +14 −0 Original line number Diff line number Diff line Loading @@ -185,6 +185,20 @@ public function testShortcutSetUnassign() { $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. */ Loading