Commit c20ea2ac 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)
parent dfe7fd83
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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);
}
+14 −0
Original line number Diff line number Diff line
@@ -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.
   */