Updated: Comment #108

Problem/Motivation

There are several problems in shortcut.module:

  1. shortcut_current_displayed_set, shortcut_default_set(), and ShortcutSetStorage::getDefaultSet() can return NULL in edge cases, which is not documented and - worse - calling code does not account for. This is a bug. (It's not a super-easy-to-trigger bug, but it's a bug nonetheless.)
  2. Shortcut module circumvents the standard patterns we have in core for checking access to entities. This is - strictly speaking - not a bug, because nothing is explicitly broken (i.e. there is no information disclosure, due to incorrect access checking), but it is very confusing and unnecessary limiting at best. Also note that Shortcut module has not been battle-tested in light of the new caching world order (e.g. #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!)) and fixing the problems that will inevitable crop up when doing so will be much easier with standard entity access logic. This is follow-up material, however
  3. There is duplicated code between shortcut.module and ShortcutSetStorage/shortcut_default_set() <=> ShortcutSetStorage::getDefaultSet() and shortcut_set_edit_access() <=> ShortcutSetAccessControlHandler::checkAccess(). This is especially unnerving because in the latter case the code is not even directly copy-pasted but "looks" different, even though the actual logic is identical.

Proposed resolution

  1. Deprecate shortcut_set_edit_access() in favor of $shortcut_set->access('update')
  2. Deprecate shortcut_set_switch_access() in favor of $user->access('switch_shortcut_set') which calls out to a new hook_user_access() implementation in Shortcut module (API addition)
  3. Deprecate shortcut_current_displayed_set() in favor of a new ShortcutSetStorage::getCurrentSet() (API addition)
  4. Deprecate shortcut_default_set() in favor of ShortcutSetStorage::getDefaultSet(). The latter is also fixed to always return a shortcut set. (Bug fix)
  5. Deprecate shortcut_renderable_links() in favor of a new $shortcut_set->getRenderableShortcuts() (API addition)
  6. Add typehints in ShortcutSetStorageInterface to ::assignUser(), unassignUser(), getAssignedToUser(). This is not an API change, just a documenation clean-up: The methods already relied on the respective objects to be passed.
  7. Adjust all calling code in core to the new methods.

Remaining tasks

RTBC the patch.

User interface changes

None.

API changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because various methods can return NULL instead of a shortcut set, but this is neither documented nor expected
Issue priority Normal because the bug is not exposed in core at the moment (but was uncovered through the cleanup)
Prioritized changes Prioritized because it is a bug fix and it greatly reduces fragility both in terms of duplicated code and in terms future improvements to the cacheability of Shortcut module. It will also lessen the pain discussed in #2419387: Remove Shortcut module from core
Disruption None.
CommentFileSizeAuthor
#201 2083123-nr-bot.txt145 bytesneeds-review-queue-bot
#199 2083123-199.patch65.54 KBsmustgrave
#199 interdiff-197-199.txt1.75 KBsmustgrave
#197 2083123-197.patch66.58 KBsmustgrave
#195 2083123-195.patch73.02 KBsmustgrave
#195 interdiff-193-195.txt0 bytessmustgrave
#193 interdiff-2083123-191-193.txt862 bytesmanuel.adan
#193 2083123-193.patch65.51 KBmanuel.adan
#191 interdiff-2083123-189-191.txt2.08 KBmanuel.adan
#191 2083123-191.patch65.77 KBmanuel.adan
#189 interdiff-2083123-185-189.txt6.4 KBmanuel.adan
#189 2083123-189.patch63.46 KBmanuel.adan
#185 interdiff_183-185.txt1.93 KBvsujeetkumar
#185 2083123-185.patch64.25 KBvsujeetkumar
#183 interdiff_181-183.txt1.04 KBvsujeetkumar
#183 2083123-183.patch64.25 KBvsujeetkumar
#181 2083123-181.patch64.05 KBvsujeetkumar
#177 interdiff_175-177.txt3.1 KBvsujeetkumar
#177 2083123-177.patch64.1 KBvsujeetkumar
#175 interdiff_174_175.txt2.83 KBanmolgoyal74
#175 2083123-175.patch63.15 KBanmolgoyal74
#174 2083123-174.patch63.06 KBsanjayk
#171 interdiff_169-171.txt1.39 KBridhimaabrol24
#171 2083123-171.patch64.2 KBridhimaabrol24
#169 interdiff_167-169.txt2.17 KBridhimaabrol24
#169 2083123-169.patch62.81 KBridhimaabrol24
#167 interdiff_165-167.txt377 bytesridhimaabrol24
#167 2083123-167.patch62.84 KBridhimaabrol24
#165 2083123-165.patch62.85 KBridhimaabrol24
#160 2083123-160.patch63.11 KBjibran
#150 shortcut_cleanup_fix-2083123-150.patch72.96 KBsavkaviktor16@gmail.com
#137 shortcut_cleanup_fix-2083123-137-8.1.x.patch62.84 KBjibran
#127 2083123-127-shortcut-cleanup.patch62.97 KBtstoeckler
#126 2083123-126-shortcut-cleanup.patch636.29 KBtstoeckler
#124 2083123-119-shortcut-cleanup.patch63.25 KBtstoeckler
#124 2083123-119-124-interdiff.txt1.27 KBtstoeckler
#119 2083123-119-shortcut-cleanup.patch63.25 KBtstoeckler
#119 2083123-114-119-interdiff.txt8.72 KBtstoeckler
#116 2083123-shortcut-user-access-test-do-not-test.patch4.08 KBtstoeckler
#114 2083123-114-shortcut-cleanup.patch52.96 KBtstoeckler
#114 2083123-110-114-tests-interdiff.txt18.13 KBtstoeckler
#114 2083123-110-114-cleanup-interdiff.txt10.39 KBtstoeckler
#110 2083123-shortcut-cleanup.patch29.87 KBtstoeckler
#110 2083123-107-110-interdiff.txt685 byteststoeckler
#107 2083123-107-shortcut-cleanup.patch29.85 KBtstoeckler
#107 2083123-105-107-interdiff.txt3.35 KBtstoeckler
#105 interdiff.txt702 byteswillzyx
#105 2083123-105.patch29 KBwillzyx
#103 interdiff.txt2.35 KBwillzyx
#103 2083123-103.patch28.99 KBwillzyx
#98 2083123-98.patch28.85 KBtstoeckler
#98 2083123-95-98-interdiff.txt6.92 KBtstoeckler
#95 2083123-94-shortcut-cleanup.patch29.57 KBtstoeckler
#95 2083123-91-94-interdiff.txt27.24 KBtstoeckler
#91 2083123-91-shortcut-manager.patch32.7 KBtstoeckler
#91 2083123-88-91-interdiff.txt1.44 KBtstoeckler
#88 2083123-88-shortcut-manager.patch32.68 KBtstoeckler
#88 2083123-86-88-interdiff.txt630 byteststoeckler
#86 2083123-86-shortcut-manager.patch32.69 KBtstoeckler
#86 2083123-74-86-interdiff-2.txt23.99 KBtstoeckler
#86 2083123-74-86-interdiff-1.txt22.33 KBtstoeckler
#74 drupal_2083123_74.patch23.31 KBXano
#74 interdiff.txt3.25 KBXano
#72 drupal_2083123_71.patch22.56 KBXano
#72 interdiff.txt12.27 KBXano
#69 drupal_2083123_69.patch21.96 KBXano
#64 interdiff.txt7.85 KBkgoel
#64 2083123-64.patch21.82 KBkgoel
#62 interdiff.txt1.47 KBkgoel
#62 2083123-62.patch23.75 KBkgoel
#60 interdiff.txt2.25 KBkgoel
#60 2083123-60.patch23.74 KBkgoel
#57 interdiff.txt970 byteskgoel
#57 2083123-57.patch23.32 KBkgoel
#55 2083123-55.patch23.3 KBkgoel
#54 2083123-54-do-not-test.patch23.3 KBkgoel
#53 2083123-53-do-not-test.patch21.71 KBkgoel
#52 2083123-52-do-not-test.patch20.12 KBkgoel
#51 2083123-51-do-not-test.patch20.19 KBkgoel
#50 2083123-50-do-not-test.patch16.9 KBkgoel
#47 2083123-47-do-not-test.patch16.37 KBkgoel
#37 shortcut-create-shortcut-manager-2083123-37.patch56.51 KBjibran
#37 interdiff.txt9.28 KBjibran
#36 shortcut-create-shortcut-manager-2083123-36.patch48.84 KBjibran
#36 interdiff.txt3.18 KBjibran
#30 shortcut-create-shortcut-manager-2083123-30.patch57.09 KBe0ipso
#25 shortcut-create-shortcut-manager-2083123-25.patch56.69 KBe0ipso
#25 interdiff-23-25.txt13.7 KBe0ipso
#23 drupal8.shortcut-module.2083123-23.patch54.87 KBjibran
#23 interdiff.txt2.86 KBjibran
#15 shortcut-create-shortcut-manager-2083123-14.patch56.6 KBe0ipso
#15 interdiff-2083123-12-14.txt10.2 KBe0ipso
#13 shortcut-create-shortcut-manager-2083123-12.patch55.99 KBe0ipso
#13 interdiff-2083123-10-12.txt3.75 KBe0ipso
#10 shortcut-create-shortcut-manager-2083123-10.patch55.99 KBe0ipso
#10 interdiff-2083123-6-10.txt4.83 KBe0ipso
#6 shortcut-create-shortcut-manager-2083123-6.patch48.86 KBe0ipso
#1 shortcut-create-shortcut-manager-2083123-1.patch4.26 KBe0ipso
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

e0ipso’s picture

First patch attempt. This is my first time with this stuff, so feel free to add links I may read on the subject along with your comments.

e0ipso’s picture

Assigned: Unassigned » e0ipso
Status: Active » Needs work
RoSk0’s picture

Status: Needs work » Needs review
jibran’s picture

Status: Needs review » Needs work

I think we should complete following things in this issue.

  1. Add following methods to ShortcutManager
  2. shortcut_set_title_exists
    shortcut_set_load
    shortcut_valid_link
    shortcut_current_displayed_set
    shortcut_admin_add_link
    shortcut_set_reset_link_weights
    shortcut_renderable_links

  3. Remove shortcut_set_edit_access now we have ShortcutSetEditAccessCheck
  4. Remove shortcut_set_switch_access now we have ShortcutSetSwitchAccessCheck
  5. Remove shortcut_link_access now we have LinkAccessCheck
  6. Inject ShortcutManager to all shortcut AccessControllers which are using above methods
  7. Inject ShortcutManager to all shortcut Controllers which are using above methods
  8. Add ShortcutManagerInterface.(needs discussion)
  9. Move ShortcutSetAccessController to Drupal\shortcut\Access namespace. (optional)
  10. Inject csrf_token service to ShortcutSetController and replace call to drupal_valid_token. (optional)
tim.plunkett’s picture

shortcut_set_load should be removed, no reason for to to exist

e0ipso’s picture

Status: Needs work » Needs review
FileSize
48.86 KB

@tim.plunkett I didn't see the way to remove shortcut_set_load since we need the callback for the 'exists' checks on machin_name form elements. I removed explicit calls to it anywhere else.

@jibran I had to do a bit more work than described on #4 to make tests pass. I also created the ShortcutManagerInterface.php as a placeholder in order to open discussion on what methods should make it there.

Marking as needs review to trigger tests.

dawehner’s picture

jibran’s picture

Status: Needs review » Needs work

Thank you @e0ipso for working on this.
Here is the minor review.

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetAccessController.php
@@ -0,0 +1,79 @@
+   * Constructor.

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetEditAccessCheck.php
@@ -17,6 +18,23 @@
+   * Constructor.

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetSwitchAccessCheck.php
@@ -17,6 +18,23 @@
+   * Constructor.

need better docs
For interface point quoting @larowlan from #1951268-120: Convert /forum and /forum/% to new router, remove forum_forum_load(), forum_get_topics(), create Forum service

all public methods are, protected don't go on the interface, see comments above

So all the public methods of a manager will go to interface.

larowlan’s picture

Issue tags: +PHPUnit

First up - great job!

  1. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkAccessCheck.php
    @@ -8,6 +8,7 @@
    +use Drupal\shortcut\ShortcutManager;
    
    @@ -17,6 +18,23 @@
    +   * @var \Drupal\shortcut\ShortcutManager
    ...
    +  function __construct(ShortcutManager $shortcut_manager) {
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetAccessController.php
    @@ -0,0 +1,79 @@
    +use Drupal\shortcut\ShortcutManager;
    ...
    +   * @var \Drupal\shortcut\ShortcutManager
    ...
    +   * @param \Drupal\shortcut\ShortcutManager $shortcut_manager
    ...
    +  function __construct(ShortcutManager $shortcut_manager) {
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetEditAccessCheck.php
    @@ -10,6 +10,7 @@
    +use Drupal\shortcut\ShortcutManager;
    
    @@ -17,6 +18,23 @@
    +   * @var \Drupal\shortcut\ShortcutManager
    ...
    +  function __construct(ShortcutManager $shortcut_manager) {
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetSwitchAccessCheck.php
    @@ -10,6 +10,7 @@
    +use Drupal\shortcut\ShortcutManager;
    
    @@ -17,6 +18,23 @@
    +   * @var \Drupal\shortcut\ShortcutManager
    ...
    +   * @param \Drupal\shortcut\ShortcutManager $shortcut_manager
    ...
    +  function __construct(ShortcutManager $shortcut_manager) {
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
    @@ -8,7 +8,9 @@
    +use Drupal\shortcut\ShortcutManager;
    
    @@ -20,6 +22,43 @@
    +   * @var \Drupal\shortcut\ShortcutManager
    ...
    +   * @param \Drupal\shortcut\ShortcutManager $shortcut_manager
    ...
    +  function __construct(CsrfTokenGenerator $csrf_token, ShortcutManager $shortcut_manager) {
    

    Can we type hint on the interface

  2. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkAccessCheck.php
    @@ -29,8 +47,8 @@ public function appliesTo() {
    +    if ($shortcut_set = entity_load('shortcut_set', $set_name)) {
    

    Can we inject the shortcut storage controller (may need to inject entity.manager and then store the shortcut storage controller on the object)

  3. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
    @@ -43,7 +82,7 @@ public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Reques
    +      \Drupal::service('shortcut.manager')->adminAddLink($link, $shortcut_set);
    

    Can this be injected?

  4. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Block/ShortcutsBlock.php
    @@ -25,8 +25,9 @@ class ShortcutsBlock extends BlockBase {
    +    $shortcutManager = \Drupal::service('shortcut.manager');
    

    We can implement ContainerFactoryPluginInterface and inject the shortcut manager

  5. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    + * Contains \Drupal\book\ShortcutManager.
    

    book => shortcut

  6. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * @return
    

    Missing type

  7. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    $shortcut_sets = &drupal_static(__FUNCTION__, array());
    

    Should this be a public static property on the object instead?

  8. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +      $account = \Drupal::currentUser();
    

    We can inject this from the services.yml file

  9. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +      $shortcut_set = entity_load('shortcut_set', $shortcut_set_name);
    

    We have the storage controller, we should use it to load.

  10. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +      $shortcut_set = shortcut_default_set($account);
    

    Can this become a method on the manager too? We would retain and mark the old function as @deprecated, and just make it wrap a call to the manager.

  11. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * @return
    

    Missing type (bool)

  12. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +  function shortcutSetTitleExists($title) {
    ...
    +  function validLink($path) {
    ...
    +  function adminAddLink($shortcut_link, &$shortcut_set) {
    ...
    +  function renderableLinks($shortcut_set = NULL) {
    ...
    +  function shortcutSetEditAccess($shortcut_set = NULL) {
    ...
    +  function shortcutSetSwitchAccess($account = NULL) {
    

    missing public|private

  13. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    $sets = $this->entityManager->getStorageController('shortcut_set')->loadMultiple();
    

    Can we use the load by properties method, passing the title instead of loading them all?

  14. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    return (!url_is_external($path) && ($this->routeProvider->getRoutesByPattern('/' . $path)->count() > 0 || menu_get_item($path))) || empty($path) || $path == '<front>';
    

    Url::isExternal($path); instead of url_is_external()

  15. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * Adds a link to the end of a shortcut set, keeping within a prescribed limit.
    ...
    +   * This function can be used, for example, when a new shortcut link is added to
    

    > 80 chars

  16. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    $menu_link = entity_create('menu_link', $shortcut_link);
    

    We have the entityManager, we can use it to get the storage controller for menu links and call ::create on that.

  17. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    $weight = -50;
    

    objects are always passed as reference - do we need the & in the function signature any more?

  18. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * @return
    

    Missing type (array)

  19. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    return menu_tree('shortcut-' . $shortcut_set->id());
    

    In order to make this object unit-testable, the call to menu_tree (which has no OO equivalent) should be inside a wrapper method, that way we can mock that method. Thoughts?

  20. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * @param \Drupal\shortcut\Entity\ShortcutSet $shortcut_set
    

    The function signature doesn't contain a type-hint to match this

  21. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * @return
    ...
    +   * @return
    

    Missing type (bool)

  22. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +    $account = \Drupal::currentUser();
    

    Can we inject this?

  23. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,257 @@
    +   * @param object $account
    

    Is it just an object? Or is it an AccountInterface? or perhaps a UserInterface?. Same story in function signature.

  24. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManagerInterface.php
    @@ -0,0 +1,13 @@
    +  // TODO: Discuss what should be the signature of this interface.
    

    This should contain any public method found in the default implementation. All of the function docblocks can be moved here and replaced with {@inheritdoc} in the default implementation.

  25. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManagerInterface.php
    @@ -0,0 +1,13 @@
    \ No newline at end of file
    
    +++ b/core/modules/shortcut/shortcut.services.yml
    @@ -1,15 +1,22 @@
    \ No newline at end of file
    

    Whitespace

  26. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php
    @@ -64,7 +64,7 @@ public function validate(array $form, array &$form_state) {
    +    if ($form_state['values']['label'] != $entity->label() && \Drupal::service('shortcut.manager')->shortcutSetTitleExists($form_state['values']['label'])) {
    

    We can inject the shortcut manager by implementing ContainerInjectionInterface.

  27. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetStorageController.php
    @@ -48,7 +48,7 @@ public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
    +    drupal_static_reset('currentDisplayedSet');
    

    Does this work? I think you might need a 'resetCache' method on the manager. Inject the manager (by implementing EntityControllerInterface) and call the resetCache method here instead.

  28. +++ b/core/modules/shortcut/shortcut.admin.inc
    @@ -322,33 +322,8 @@ function shortcut_link_add_submit($form, &$form_state) {
    -function shortcut_admin_add_link($shortcut_link, &$shortcut_set) {
    
    +++ b/core/modules/shortcut/shortcut.module
    @@ -144,77 +144,6 @@ function shortcut_admin_paths() {
    -function shortcut_set_edit_access($shortcut_set = NULL) {
    ...
    -function shortcut_set_switch_access($account = NULL) {
    ...
    -function shortcut_link_access($menu_link) {
    
    @@ -244,24 +173,6 @@ function shortcut_set_load($id) {
    -function shortcut_set_reset_link_weights(&$shortcut_set) {
    
    @@ -295,45 +206,6 @@ function shortcut_set_unassign_user($account) {
    -function shortcut_current_displayed_set($account = NULL) {
    
    @@ -366,66 +238,6 @@ function shortcut_default_set($account = NULL) {
    -function shortcut_set_title_exists($title) {
    ...
    -function shortcut_valid_link($path) {
    

    This needs to be retained as just a wrapper to the service and marked @deprecated

  29. +++ b/core/modules/shortcut/shortcut.module
    @@ -466,13 +279,13 @@ function shortcut_preprocess_page(&$variables) {
    -      $query['token'] = drupal_get_token('shortcut-add-link');
    ...
    +      $query['token'] = \Drupal::csrfToken()->get('shortcut-add-link');
    

    Out of scope?

Finally can we get a follow-up to add some phpunit tests for the manager?

e0ipso’s picture

Status: Needs work » Needs review
Issue tags: -PHPUnit
FileSize
4.83 KB
55.99 KB

@larowlan thank you for your comments. I implemented your suggestions, but I have some comments about 27.

Does this work? I think you might need a 'resetCache' method on the manager. Inject the manager (by implementing EntityControllerInterface) and call the resetCache method here instead.

I modified the implementation adding the complete class namespace and adding the method name to avoid cache clashes. I checked and found that CacheBackendInterface is using the same approach.

Also I didn't wrap

shortcut_link_access

because is not used anywhere in the current 8.x branch and polluted unnecessarily the manager.

Tests turned green in my local.

e0ipso’s picture

@larowlan thank you for your comments. I implemented your suggestions, but I have some comments about 27.

Does this work? I think you might need a 'resetCache' method on the manager. Inject the manager (by implementing EntityControllerInterface) and call the resetCache method here instead.

I modified the implementation adding the complete class namespace and adding the method name to avoid cache clashes. I checked and found that CacheBackendInterface is using the same approach.

Also I didn't wrap shortcut_link_access because is not used anywhere in the current 8.x branch and polluted unnecessarily the manager.

Tests turned green in my local.

jibran’s picture

Status: Needs review » Needs work

Thanks @larowlan for the detailed review. once again great work by @e0ipso.
Here are some minor issues.

  1. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkAccessCheck.php
    @@ -17,6 +20,39 @@
    +   * Constructor.
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetAccessController.php
    @@ -0,0 +1,79 @@
    +   * Constructor.
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetEditAccessCheck.php
    @@ -17,6 +18,23 @@
    +   * Constructor.
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetSwitchAccessCheck.php
    @@ -17,6 +18,23 @@
    +   * Constructor.
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
    @@ -20,6 +22,43 @@
    +   * Constructor.
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php
    @@ -7,12 +7,40 @@
    +   * Constructor.
    

    need better doc.

  2. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,256 @@
    +   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
    +   *   Injected dependency injector container to inject 'current_user', which
    +   *   is in a narrower scope.
    ...
    +    $this->currentUser = $container->get('current_user');
    

    What is narrower scope? I still think we should inject current_user service.

  3. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,256 @@
    +      $shortcut_set = shortcut_default_set($account);
    

    We can use $this->defaultSet() here.

  4. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,256 @@
    +    $suggestions = array_reverse(\Drupal::moduleHandler()->invokeAll('shortcut_default_set', array($account)));
    

    moduleHandler Injection

  5. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManagerInterface.php
    @@ -0,0 +1,133 @@
    +   * @param AccountInterface $account
    ...
    +   * @param AccountInterface $account
    ...
    +   * @param AccountInterface $account
    

    use complete namespace.

  6. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManagerInterface.php
    @@ -0,0 +1,133 @@
    +   * @param $title
    ...
    +   * @param $link
    

    Typehint missing.

  7. +++ b/core/modules/shortcut/shortcut.services.yml
    @@ -1,15 +1,22 @@
    \ No newline at end of file
    

    whitespace.

e0ipso’s picture

Status: Needs work » Needs review
FileSize
3.75 KB
55.99 KB

Ooops, there were some changes pending to commit.

Status: Needs review » Needs work

The last submitted patch, shortcut-create-shortcut-manager-2083123-12.patch, failed testing.

e0ipso’s picture

Status: Needs work » Needs review
FileSize
10.2 KB
56.6 KB

Adding feedback from #12.

Also, @jibran asked me in IRC to clarify the injection of the current_user service. I could not find an example in all of our codebase on how to inject it. If you pay attention to core.services.yml you'll see that the current_user service has scope: request in its declaration. This makes services of scope wider than request to not be able to inject it. Also, if you see the implementation of \Drupal::currentUser() you'll see that we are using the dependency injection container to get the current_user. What I did was mimic that behavior and inject the dependency injection container to the manager to be able to inject the current_user service in the constructor (see the constructor of ShortcutManager.php to make sense out of this).

A part from that, I updated the constructor documentation à la BookManager.php.

e0ipso’s picture

Issue tags: +PHPUnit
e0ipso’s picture

Read #2076411: Remove the request scope from the current user service for more details about the current_user injection problem. The solution there was to remove the request scope from the current_user service to unblock these issues and deal with it later in #2102027: Add back the request scope to the current user service.

I guess that I'll need to rework the issue to inject the current_user service as all of the others.

Status: Needs review » Needs work
Issue tags: -PHPUnit, -API change, -WSCCI, -WSCCI-conversion

The last submitted patch, shortcut-create-shortcut-manager-2083123-14.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +PHPUnit, +API change, +WSCCI, +WSCCI-conversion

The last submitted patch, shortcut-create-shortcut-manager-2083123-14.patch, failed testing.

larowlan’s picture

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetAccessController.php
@@ -27,7 +27,7 @@ class ShortcutSetAccessController extends EntityAccessController implements Enti
+   * Constructs ShortcutSetAccessController objects.

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetEditAccessCheck.php
@@ -25,7 +25,7 @@ class ShortcutSetEditAccessCheck implements StaticAccessCheckInterface {
+   * Constructs ShortcutSetEditAccessCheck objects.

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetSwitchAccessCheck.php
@@ -25,7 +25,7 @@ class ShortcutSetSwitchAccessCheck implements StaticAccessCheckInterface {
+   * Constructs ShortcutSetSwitchAccessCheck objects.

+++ b/core/modules/shortcut/lib/Drupal/shortcut/Controller/ShortcutSetController.php
@@ -36,7 +36,7 @@ class ShortcutSetController extends ControllerBase {
+   * Constructs ShortcutSetController objects.

object

Yeah we've seen issues with the current_user service on other issues.

andypost’s picture

jibran’s picture

Status: Needs work » Needs review
FileSize
2.86 KB
54.87 KB

Reroll and fixes for #21.

Status: Needs review » Needs work

The last submitted patch, drupal8.shortcut-module.2083123-23.patch, failed testing.

e0ipso’s picture

Reworking this to (hopefully) get it back to green.

e0ipso’s picture

Status: Needs work » Needs review
jibran’s picture

Yay!! patch is green. I think it is ready to fly. I have updated issue summary and I think we can remove shortcut_set_load() method now.

jibran’s picture

Issue summary: View changes

Updated issue summary.

jibran’s picture

Status: Needs review » Needs work

The last submitted patch, 25: shortcut-create-shortcut-manager-2083123-25.patch, failed testing.

e0ipso’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
57.09 KB

Rerolled #25.

Status: Needs review » Needs work

The last submitted patch, 30: shortcut-create-shortcut-manager-2083123-30.patch, failed testing.

The last submitted patch, 30: shortcut-create-shortcut-manager-2083123-30.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 30: shortcut-create-shortcut-manager-2083123-30.patch, failed testing.

e0ipso’s picture

Assigned: e0ipso » Unassigned
jibran’s picture

Status: Needs work » Needs review
FileSize
3.18 KB
48.84 KB

Reroll.

jibran’s picture

andypost’s picture

Implemenation of shortcutSetEditAccess() and shortcutSetSwitchAccess() in manager looks strange suppose they should be access checkrs, also it's not clear the reason of moving other methods to manager because not sure there's any sense to make them overridable

  1. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +  public function shortcutSetTitleExists($title) {
    

    suppose this function should live in controller where used

  2. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +  public function validLink($path) {
    

    same

  3. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +  public function shortcutSetEditAccess(ShortcutSetInterface $shortcut_set = NULL, AccountInterface $user = NULL) {
    ...
    +  public function shortcutSetSwitchAccess(AccountInterface $account = NULL, AccountInterface $user = NULL) {
    

    Suppose better leave this ones as access controllers

  4. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutLinksTest.php
    @@ -60,7 +60,7 @@ public function testShortcutLinkAdd() {
    -      $saved_set = shortcut_set_load($set->id());
    +      $saved_set = entity_load('shortcut_set', $set->id());
    
    @@ -94,7 +94,7 @@ public function testShortcutLinkRename() {
    +    $saved_set = entity_load('shortcut_set', $set->id());
    

    Better to file new issue to get rid of shortcut_set_load()

larowlan’s picture

  1. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Block/ShortcutsBlock.php
    @@ -20,14 +23,37 @@
    +  /**
    +   * @param \Drupal\shortcut\ShortcutManagerInterface $shortcut_manager
    +   *   Injected shortcut manager.
    +   */
    

    Missing short description.

  2. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +   * @param \Drupal\Core\Extension\ModuleHandler $module_handler
    ...
    +   * @param \Drupal\Core\Routing\RouteProvider $route_provider
    ...
    +   * @param \Drupal\Core\Path\AliasManager $alias_manager
    ...
    +   * @param \Drupal\Core\Entity\EntityManager $entity_manager
    

    Should typehint ModuleHandlerInterface, AliasManagerInterface, RouteProviderInterface and EntityManagerInterface?

  3. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +    $shortcut_sets = &drupal_static('Drupal\shortcut\ShortcutManager::currentDisplayedSet', array());
    

    should use a static class property?

    static::$currentDisplayedSet
    

    and

    static protected $currentDisplayedSet;
    
  4. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +    return (!Url::isExternal($path) && ($this->routeProvider->getRoutesByPattern('/' . $path)->count() > 0 || menu_get_item($path))) || empty($path) || $path == '<front>';
    

    Do we still support menu_get_item()? pretty sure there's an effort to remove that.

  5. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +    foreach ($suggestions as $name) {
    +      if ($shortcut_set = $this->shortcutSetStorageController->load($name)) {
    +        break;
    +      }
    +    }
    

    would this be better off to just use reset() to load the first item from the suggestions?

  6. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +   * This is an OO wrapper for menu_tree since this function has no OO variant.
    

    Short description > 80 chars.

  7. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManagerInterface.php
    @@ -0,0 +1,129 @@
    + * Contains \Drupal\book\ShortcutManager.
    

    %s/ShortcutManager/ShortcutManagerInterface

  8. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +    $menu_link = $this->entityManager->getStorageController('menu_link')->create($shortcut_link);
    

    Should this be saving menu_link entities now? I thought shortcut entities were decoupled form menu_links? If so, we are missing test coverage.

  9. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManager.php
    @@ -0,0 +1,265 @@
    +    $shortcuts = $this->entityManager->getStorageController('shortcut')->loadByProperties(array('shortcut_set' => $shortcut_set->id()));
    

    This would seem to confirm my suspicions that the entity type should be shortcut and not menu_link

  10. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutManagerInterface.php
    @@ -0,0 +1,129 @@
    +   * Adds a link to the end of a shortcut set, keeping within a prescribed limit.
    

    >80 chars

  11. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php
    @@ -64,8 +92,8 @@ public function validate(array $form, array &$form_state) {
    +      $this->setFormError('label', $form_state, t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label'])));
    

    this->t()?

  12. +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetStorageController.php
    @@ -33,7 +33,7 @@ public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
    +    drupal_static_reset('Drupal\shortcut\ShortcutManager::currentDisplayedSet');
    

    ah, that's why you used drupal_static instead of a static property, although you could make the property public or add a public static reset method, increasing unit-testability. (drupal_static isn't unit testable)

  13. +++ b/core/modules/shortcut/shortcut.module
    @@ -128,37 +119,21 @@ function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) {
    + *   The machinename of the shortcut set to load.
    

    unrelated change? machinename is not a word so I would say that machine-name or machine name is more correct? But could be a standard I'm not aware of?

ParisLiakos’s picture

Status: Needs review » Needs work

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 37: shortcut-create-shortcut-manager-2083123-37.patch, failed testing.

tstoeckler’s picture

Issue tags: -API change

So because we don't actually remove the functions here but only deprecate them the only API changes are:

  1. Moving
    • ShortcutSetAccessController
    • ShortcutAccessController

    into the Access sub-namespace

  2. Changing the constructor of
    • ShortcutSetFormController
    • ShortcutFormController
    • ShortcutsBlock
    • ShortcutSetController
    • ShortcutSetSwitchAccessCheck
    • ShortcutSetEditAccessCheck
    • ShortcutSetAccessController
    • ShortcutAccessController

    to inject the shortcut manager

The first can just be reverted and the second one we generally don't consider disruptive. In this particular case there's not really much of a use-case of subclassing these, so I think these should still be acceptable in beta. Will add a beta evaluation, but I think we're still good to go here.

If we're super adament about BC and don't want to change the constructors we could wrap add calls to \Drupal::service('shortcut.manager') in those classes, but for IMO that would be a bit silly.

Will review this now.

tstoeckler’s picture

Didn't get all the way through, but here goes:

  1. similarity index 69%
    rename from core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php
    
    rename from core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php
    rename to core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutAccessController.php
    
    @@ -2,15 +2,17 @@
    - * Contains \Drupal\shortcut\ShortcutAccessController.
    + * Contains \Drupal\shortcut\Access\ShortcutAccessController.
    ...
    -namespace Drupal\shortcut;
    +namespace Drupal\shortcut\Access;
    
    similarity index 52%
    rename from core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetAccessController.php
    
    rename from core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetAccessController.php
    rename to core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetAccessController.php
    
    @@ -2,19 +2,48 @@
    - * Contains \Drupal\shortcut\ShortcutSetAccessController.
    + * Contains \Drupal\shortcut\Access\ShortcutSetAccessController.
    ...
    -namespace Drupal\shortcut;
    +namespace Drupal\shortcut\Access;
    
    @@ -22,7 +22,7 @@
    - *     "access" = "Drupal\shortcut\ShortcutAccessController",
    + *     "access" = "Drupal\shortcut\Access\ShortcutAccessController",
    
    @@ -20,7 +20,7 @@
    - *     "access" = "Drupal\shortcut\ShortcutSetAccessController",
    + *     "access" = "Drupal\shortcut\Access\ShortcutSetAccessController",
    

    As mentioned above let's revert this.

  2. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutAccessController.php
    @@ -26,6 +28,13 @@ class ShortcutAccessController extends EntityAccessController implements EntityC
    +   * Stores the shortcut Manager.
    
    @@ -34,10 +43,13 @@ class ShortcutAccessController extends EntityAccessController implements EntityC
    +   *   Injected ShortcutManager service.
    

    "The shortcut manager" would be more standard I think.

  3. +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutAccessController.php
    @@ -56,7 +69,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ
       protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
         if ($shortcut_set = $this->shortcutSetStorage->load($entity->bundle())) {
    -      return shortcut_set_edit_access($shortcut_set, $account);
    +      return $this->shortcutManager->shortcutSetEditAccess($shortcut_set, $account);
         }
       }
    
    @@ -65,7 +78,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
       protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
         if ($shortcut_set = $this->shortcutSetStorage->load($entity_bundle)) {
    -      return shortcut_set_edit_access($shortcut_set, $account);
    +      return $this->shortcutManager->shortcutSetEditAccess($shortcut_set, $account);
         }
       }
    
    +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/ShortcutSetEditAccessCheck.php
    @@ -28,17 +46,8 @@ public function appliesTo() {
       public function access(Route $route, Request $request, AccountInterface $account) {
    -    $account = \Drupal::currentUser();
         $shortcut_set = $request->attributes->get('shortcut_set');
    -    // Sufficiently-privileged users can edit their currently displayed shortcut
    -    // set, but not other sets. Shortcut administrators can edit any set.
    -    if ($account->hasPermission('administer shortcuts')) {
    -      return static::ALLOW;
    -    }
    -    if ($account->hasPermission('customize shortcut links')) {
    -      return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set() ? static::ALLOW : static::DENY;
    -    }
    -    return static::DENY;
    +    return $this->shortcutManager->shortcutSetEditAccess($shortcut_set, $account) ? static::ALLOW : static::DENY;
       }
    
    +++ b/core/modules/shortcut/shortcut.module
    @@ -103,21 +101,14 @@ function shortcut_admin_paths() {
    + * @deprecated Use \Drupal\shortcut\ShortcutManager::shortcutSetEditAccess()
    + *
    ...
     function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) {
    -  $account = \Drupal::currentUser();
    -  // Sufficiently-privileged users can edit their currently displayed shortcut
    -  // set, but not other sets. Shortcut administrators can edit any set.
    -  if ($account->hasPermission('administer shortcuts')) {
    -    return TRUE;
    -  }
    -  if ($account->hasPermission('customize shortcut links')) {
    -    return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set();
    -  }
    -  return FALSE;
    +  return \Drupal::service('shortcut.manager')->shortcutSetEditAccess($shortcut_set);
     }
    

    This indirection is awkward in my opinion. The ShortcutSetAccessController should be the canonical source for controlling access to shortcut sets. So if the shortcut access depends on the shortcut set edit access, ShortcutAccessController should get ShortcutSetAccessController injected. ShortcutManager has no business in all of this. shortcut_set_edit_access() should then just call \Drupal::entityManager()->getAccessControlHandler('shortcut_set')->edit($shortcut_set, 'edit')

kgoel’s picture

working on this

kgoel’s picture

FileSize
16.37 KB

This is still WIP patch and it's nowhere ready to be reviewed.

Reroll of https://www.drupal.org/node/2083123#comment-8278245 was impossible since the patch is more than year old and core changed significantly in a year :)

kgoel’s picture

It's interesting that PhpStorm reformatting doesn't add new line at the EOF.

kgoel’s picture

I am an idiot - moved shortcut.services.yml to src folder :(

kgoel’s picture

WIP patch

kgoel’s picture

FileSize
20.19 KB

still WIP

kgoel’s picture

FileSize
20.12 KB

WIP

kgoel’s picture

FileSize
21.71 KB
kgoel’s picture

kgoel’s picture

Status: Needs work » Needs review
FileSize
23.3 KB

Status: Needs review » Needs work

The last submitted patch, 55: 2083123-55.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
23.32 KB
970 bytes

Status: Needs review » Needs work

The last submitted patch, 57: 2083123-57.patch, failed testing.

jibran’s picture

Issue tags: +Need tests

Very nice work @kgoel. Let's add some phpunit tests for ShortcutManager as well.

  1. +++ b/core/modules/shortcut/shortcut.module
    @@ -55,17 +55,8 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
    -  $account = \Drupal::currentUser();
    ...
    +  $user = \Drupal::currentUser();
    

    Let's revert this change.

  2. +++ b/core/modules/shortcut/shortcut.module
    @@ -81,33 +72,7 @@ function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) {
     function shortcut_set_switch_access($account = NULL) {
       $user = \Drupal::currentUser();
    

    Why do we have $account and $user both here?

  3. +++ b/core/modules/shortcut/src/ShortcutSetStorage.php
    @@ -82,7 +82,7 @@ public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
    -    drupal_static_reset('shortcut_current_displayed_set');
    +    drupal_static_reset('Drupal\shortcut\ShortcutManager::currentDisplayedSet');
    

    I'm sure we can add some property in ShortcutManger and unset it here.

kgoel’s picture

Status: Needs work » Needs review
FileSize
23.74 KB
2.25 KB

@jibran thanks for the review.

Let's revert this change.

I am not sure about this. please see shortcutSetEditAccess?

Why do we have $account and $user both here?

Fixed

I'm sure we can add some property in ShortcutManger and unset it here.

Can you please be specific?

hopefully this patch will fix some fails.

Status: Needs review » Needs work

The last submitted patch, 60: 2083123-60.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
23.75 KB
1.47 KB

Status: Needs review » Needs work

The last submitted patch, 62: 2083123-62.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
21.82 KB
7.85 KB

Status: Needs review » Needs work

The last submitted patch, 64: 2083123-64.patch, failed testing.

kerby70’s picture

Issue tags: -Need tests +Needs tests

Correcting non standard tag 'Need tests' to 'Needs tests'

jibran queued 64: 2083123-64.patch for re-testing.

The last submitted patch, 64: 2083123-64.patch, failed testing.

Xano’s picture

Re-roll.

I'm already working on another version of the patch to fix a few more things.

jibran’s picture

I know @tstoeckler has posted a very convincing reason in #44 but let's get a proper approval first from any core committer.

Status: Needs review » Needs work

The last submitted patch, 69: drupal_2083123_69.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
12.27 KB
22.56 KB

One of the recurring errors in previous patches was that class dependencies were referred to as services. This is wrong. Services are an application-level concept. Classes don't care if their dependencies are also defined as services somewhere else, or are mocks, or are neither.
TLDR; when writing classes, don't use the terminology service. It's irrelevant and misleading documentation.

This patch fixes the documentation, injects the current user into the shortcut manager, replaces drupal_static() usage in the manager, and makes more use of default method arguments.

Status: Needs review » Needs work

The last submitted patch, 72: drupal_2083123_71.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
3.25 KB
23.31 KB
kgoel’s picture

Its good to see some progress here but there was a concern if there is a need to rewrite shortcut module in 8.0.x that resulted me to stop working on this issue.

I haven't reviewed the patch but looked at it briefly - I am under the impression that DI can't be added to the constructor as this is consider as API change and we are in beta right now. (I was told not to and thats why more service).

Xano’s picture

I haven't reviewed the patch but looked at it briefly - I am under the impression that DI can't be added to the constructor as this is consider as API change and we are in beta right now. (I was told not to and thats why more service).

Which constructors are we talking about here? The shortcut manager is new and we can build that whichever way we want. The block is a final class for all intents and purposes, so we can change that too.

kgoel’s picture

+++ b/core/modules/shortcut/src/ShortcutAccessControlHandler.php
@@ -30,16 +30,26 @@ class ShortcutAccessControlHandler extends EntityAccessControlHandler implements
-  public function __construct(EntityTypeInterface $entity_type, ShortcutSetStorageInterface $shortcut_set_storage) {
+  public function __construct(EntityTypeInterface $entity_type, ShortcutSetStorageInterface $shortcut_set_storage, ShortcutManagerInterface $shortcut_manager) {

I was talking about this class but correct me if I am wrong.

Xano’s picture

Ah yeah. I would say the same logic applies there: the class is more or less final (it's definitely not designed to be extended), so I think adding an extra constructor argument there is fine. If any child classes happen to exist (small chance), it's easier for them to copy the extra constructor argument rather than to set up \Drupal during unit tests.

kgoel’s picture

Ah yeah. I would say the same logic applies there: the class is more or less final (it's definitely not designed to be extended), so I think adding an extra constructor argument there is fine. If any child classes happen to exist (small chance), it's easier for them to copy the extra constructor argument rather than to set up \Drupal during unit tests.

why would you say that class is more or less final - I don't see the word final in the class (sorry, I am trying to understand your point).

unrelated - I don't understand why in some issues, it's ok to add parameters in the constructor. Is it based on the priority of the issue?

Xano’s picture

A final class cannot be extended. These classes aren't technically final, but were never designed to be extended. Assuming they are indeed never extended, adding constructor arguments does not break anything.

unrelated - I don't understand why in some issues, it's ok to add parameters in the constructor. Is it based on the priority of the issue?

Adding parameters is not a bad thing per se. It will however break child classes outside of core, because we cannot update them in the same patch. Depending on whether there are child classes (how big the disruption is), the BC break may or may not be a problem.

kgoel’s picture

A final class cannot be extended. These classes aren't technically final, but were never designed to be extended. Assuming they are indeed never extended, adding constructor arguments does not break anything.

I know that final class cannot be extended. In this case, ShortcutAccessControlHandler.php, you think that this won't be extended. I guess I need to understand design pattern to convince myself.

cilefen’s picture

Issue tags: +Needs beta evaluation

This needs a beta evaluation. Shouldn't the old functions be marked deprecated in this issue or in a follow-up issue?

Crell’s picture

I wouldn't view a constructor as part of an API by default. Only if specifically called out as such.

tstoeckler’s picture

Status: Needs review » Needs work

In addition to the below the current patch is still work in progress, so undoubtedly "needs work".

  1. +++ b/core/modules/shortcut/src/ShortcutManager.php
    @@ -0,0 +1,230 @@
    +  /**
    +   * The entity manager.
    +   *
    +   * @var \Drupal\Core\Entity\EntityManager
    +   */
    +  protected $entityManager;
    ...
    +  /**
    +   * The shortcut set storage.
    +   *
    +   * @var \Drupal\shortcut\ShortcutSetStorageInterface
    +   */
    +  protected $shortcutSetStorage;
    

    Either we should inject the shortcut storage (which is what the entity manager is used for) instead of the entity manager itself just like we currently do the shortcut set storage - or we should use the entity manager to fetch the shortcut set storage and not inject the shortcut set storage. (I.e. either inject both shortcut storage and shortcut set storage or neither)

    I would prefer the former but I don't really care.

  2. +++ b/core/modules/shortcut/src/ShortcutManager.php
    @@ -0,0 +1,230 @@
    +  /**
    +   * The alias manager.
    +   *
    +   * @var \Drupal\Core\Path\AliasManager
    +   */
    +  protected $aliasManager;
    +
    +  /**
    +   * The route provider.
    +   *
    +   * @var \Drupal\Core\Routing\RouteProvider
    +   */
    +  protected $routeProvider;
    

    It seems both of these are unnecessary dependencies, or am I missing something?

  3. +++ b/core/modules/shortcut/src/ShortcutManagerInterface.php
    @@ -0,0 +1,101 @@
    +  public function shortcutSetTitleExists($title);
    

    As shortcut_set_title_exists() has no usages left and only exists for BC purposes we should not introduce a method for this here. Let's just leave the function as is, and then kill it without replacement in D9.

  4. +++ b/core/modules/shortcut/src/ShortcutManagerInterface.php
    @@ -0,0 +1,101 @@
    +  public function renderableLinks(ShortcutSetInterface $shortcut_set = NULL);
    

    As this is just a different way to display the links (i.e. it is conceptually similar to ShortcutSet::getShortcuts() IMO we should move this onto ShortcutSetInterface instead.

  5. +++ b/core/modules/shortcut/src/ShortcutManagerInterface.php
    @@ -0,0 +1,101 @@
    +  public function shortcutSetEditAccess(ShortcutSetInterface $shortcut_set = NULL, AccountInterface $account = NULL);
    ...
    +  public function shortcutSetSwitchAccess(AccountInterface $account = NULL, AccountInterface $user = NULL);
    

    These two strike me as rather odd. We already have a ShortcutSetAccessControlHandler so I think we should put the logic in there. We should document that a dedicated 'switch' operation is supported and then put everything in ShortcutSetAccessControllerHandler::checkAccess(). Then the current methods can look like

    function shortcut_set_edit_access($shortcut_set = NULL) {
      if (!$shortcut_set) {
        $shortcut_set = shortcut_current_displayed_set();
      }
      return $shortcut_set->access('edit', NULL, TRUE);
    }
    
    function shortcut_set_switch_access($account = NULL) {
      $shortcut_set = shortcut_current_displayed_set();
      return $shortcut_set->access('switch', $account, TRUE);
    }
    
  6. +++ b/core/modules/shortcut/src/ShortcutSetStorage.php
    @@ -82,7 +82,7 @@ public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
    -    drupal_static_reset('shortcut_current_displayed_set');
    +    drupal_static_reset('Drupal\shortcut\ShortcutManager::currentDisplayedSet');
    

    The specified variable doesn't actually exist. More importantly, drupal_static_reset() (by design) does not work with class variables. We could add a reset() method to ShortcutManager that does this, but that would still mask the larger problem IMO: We have circular dependency here, between ShortcutManager and ShortcutSetStorage. ShortcutManager calls ShortcutSetStorage to load the assigned shortcut set and ShortcuSetStorage wants to reset the static in ShortcutManager when a new assignment is made. We should fix that properly. I see two possible ways out:

    1. Move ShortcutManager::currentDisplayedSet() into ShortcutSetStorage
    2. Add a assignUser() method to ShortcutManager which proxies to the same method in ShortcutSetStorage and resets its own storage.

    I prefer the second option because that keeps ShortcutSetStorage strictly about storage.

tstoeckler’s picture

Assigned: Unassigned » tstoeckler

Taking a stab at this

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
22.33 KB
23.99 KB
32.69 KB

Here we go.

This finishes the clean-up:
- Adds @deprecated to all legacy functions
- Removes usages of them in favor of ShortcutManager et al.

Also addressed #84
I was wrong in #84.5: Switching shortcut set is not actually an operation on shortcut sets themselves, it is an operation on user entities. So I implemented the access logic according to that, so it's now possible to do $user->access('switch_shortcut_set'). #2446195: Move the {shortcut_set_users} table to a proper field on the user entity will clarify this problem-space further, hopefully in D8. It will also deprecate the assignUser() and unassignUser() methods alltogether so if you're not too fond of them now (additionally) living on ShortcutManager see you there! ;-)

In addition I took the liberty of modernizing the new API a bit:
- Renamed functions (currentDisplayedSet() -> getCurrentSet(), defaultSet() -> getDefaultSet()
- Removed the optionality of various $account parameters. It should be upon the caller to decide which account should be checked.

Let's see what I broke :-)

Sorry for the 2 interdiffs, I had to merge in between. It's a bit unfortunate because the second interdiff in some places changes things I did in the 1 one, so it might actually make sense to take a look at the whole patch.

Status: Needs review » Needs work

The last submitted patch, 86: 2083123-86-shortcut-manager.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
Issue tags: +Needs issue summary update
FileSize
630 bytes
32.68 KB

Sorry.

Status: Needs review » Needs work

The last submitted patch, 88: 2083123-88-shortcut-manager.patch, failed testing.

tstoeckler’s picture

+++ b/core/modules/shortcut/src/ShortcutAccessControlHandler.php
@@ -57,7 +57,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
-      return shortcut_set_edit_access($shortcut_set, $account);
+      return $shortcut_set->access('update', $account);

@@ -69,7 +69,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
-      return shortcut_set_edit_access($shortcut_set, $account);
+      return $shortcut_set->access('update', $account);

These should pass TRUE as the third parameter.

Will fix in a minute.

(Sorry for the d.o debugging... :-/)

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
1.44 KB
32.7 KB

Next try.

Status: Needs review » Needs work

The last submitted patch, 91: 2083123-91-shortcut-manager.patch, failed testing.

tstoeckler’s picture

So the very rare condition that ShortcutManager::getDefaultSet() return NULL does actually happen. This was just masked by coincidence (and lack of docs) before. In fixing this I found ShortcutSetStorage::getDefaultSet() which was introduced way back in #1978976: Convert shortcut_set_switch to a Controller. It is a direct copy of shortcut_default_set() now ShortcutManager::getDefaultSet(). In other words, the latter is completely unnecessary. So since the assignUser()/unassignUser() methods are really just proxies, the only "real" method left on ShortcutManager is getCurrentSet(). At that point I think it's overkill to introduce a whole service for a single (not very complicated) method, that only acts as a static cache for ShortcutSetStorage in the first place. Will try that out now.

...and also make ShortcutManager::getDefaultSet() always return a shortcut set.

jibran’s picture

Awesome work @tstoeckler. I think after the green patch and a unit test for ShortcutManager we'll be ready.

+++ b/core/modules/shortcut/shortcut.routing.yml
@@ -92,6 +92,6 @@ shortcut.set_switch:
-    _custom_access: 'Drupal\shortcut\Form\SwitchShortcutSet::checkAccess'
+    _entity_access: 'user.switch_shortcut_set'

I think we should move this part to follow up seems out of scope here it will also reduce the patch size. Another issue which will help in reducing the changes made here is #2502151: Convert shortcut block to view.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
27.24 KB
29.57 KB

Here we go. No more ShortcutManager. This patch feels a lot better to me personally, but I won't tackle the title and issue summary update until someone else chimes in on the recent direction, maybe @jibran?

Let's see if this passes.

X-Post with #94. I'm fine with moving that to a follow-up, will fix that in the next patch.

Status: Needs review » Needs work

The last submitted patch, 95: 2083123-94-shortcut-cleanup.patch, failed testing.

jibran’s picture

Issue tags: -PHPUnit

This looks better already. I think this is a right direction given that for comment module they are trying to split it in #2188287: Split CommentManager in two. This is good step.

  1. +++ b/core/modules/shortcut/shortcut.module
    @@ -53,53 +55,47 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
    +  if (!isset($user)) {
    

    $user will always be set.

  2. +++ b/core/modules/shortcut/src/Entity/ShortcutSet.php
    @@ -126,4 +127,41 @@ public function getShortcuts() {
    +  public function getRenderableLinks() {
    

    getRenderableLinks seems little misplaced. If we'll rename it to getRenderableShortcutLinks or getRenderableShortcuts. I think getRenderableShortcuts is much better as we already have getShortcuts.

  3. +++ b/core/modules/shortcut/src/Plugin/Block/ShortcutsBlock.php
    @@ -20,14 +23,61 @@
    +   * The shortcut manager.
    

    No shortcut manger anymore.

  4. +++ b/core/modules/shortcut/src/ShortcutSetInterface.php
    @@ -34,4 +34,12 @@ public function resetLinkWeights();
    +   * Returns a renderable array of links for the shortcuts of this shortcut set.
    

    How about "Returns a renderable array of shortcut links for this shortcut set"?

  5. +++ b/core/modules/shortcut/src/ShortcutSetStorage.php
    @@ -115,6 +123,30 @@ public function countAssignedUsers(ShortcutSetInterface $shortcut_set) {
    +  public function getCurrentSet(AccountInterface $account) {
    

    This makes ton of sense.

  6. +++ b/core/modules/shortcut/src/ShortcutSetStorage.php
    @@ -115,6 +123,30 @@ public function countAssignedUsers(ShortcutSetInterface $shortcut_set) {
    +
    +
    

    one space too many.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
6.92 KB
28.85 KB
tstoeckler’s picture

Thanks for the review, #98 should address it, and hopefully fix the tests. I also rolled in the fix for #94.

Status: Needs review » Needs work

The last submitted patch, 98: 2083123-98.patch, failed testing.

tstoeckler’s picture

Assigned: tstoeckler » Unassigned

Will try to tackle the test fails, but this no longer needs to be assigned to me.

willzyx’s picture

+++ b/core/modules/shortcut/src/Plugin/Block/ShortcutsBlock.php
@@ -20,14 +23,61 @@
+  function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, AccountInterface $account) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+    $this->shortcutSetStorage = $entity_manager;
+    $this->account = $account;
+  }

should be $this->shortcutSetStorage = $entity_manager->getStorage('shortcut_set');
With this fix the tests should pass

willzyx’s picture

Status: Needs work » Needs review
FileSize
28.99 KB
2.35 KB

Status: Needs review » Needs work

The last submitted patch, 103: 2083123-103.patch, failed testing.

willzyx’s picture

Status: Needs work » Needs review
FileSize
29 KB
702 bytes

Added check for the very rare case that Shortcut module has been enabled but its configuration has not yet been installed.

dawehner’s picture

Issue tags: -WSCCI, -WSCCI-conversion

Web services != services

tstoeckler’s picture

I was really not a fan of adjusting our API for this extreme edge case. In particular because A) The |null type-hint would have to be added to getDefaultSet() as well (and have to be documented there as well) and in theory we would have to adapt all usages of those two methods to account for a NULL return value. I don't think that is a very sane API. Instead in this patch we create a stub shortcut set in the very rare edge case that the default one doesn't exist.

I have some very strange failures locally but I sincerely hope they are specific to my setup, we'll see.

Status: Needs review » Needs work

The last submitted patch, 107: 2083123-107-shortcut-cleanup.patch, failed testing.

tstoeckler’s picture

Title: Create ShortcutManager » Shortcut cleanup: Fix bug during config import, remove duplicated code, deprecate legacy functions
Category: Task » Bug report
Issue summary: View changes
Related issues: +#1978952: Convert shortcut_set_add to a Controller

Updated title + issue summary and added beta evaluation. Also marked as bug, because of the shortcut_set_default() issue. It was only triggered as part of the other changes here, but it is a bug nonetheless, just happens to be not caught by our current test coverage.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
685 bytes
29.87 KB

This should be green.

tim.plunkett’s picture

+++ b/core/modules/shortcut/shortcut.module
@@ -53,56 +55,47 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
+ *   Deprecated in 8.x, will be removed in 9.x. Use

@@ -111,6 +104,30 @@ function shortcut_set_switch_access($account = NULL) {
+ *   Deprecated in 8.x, will be removed in 9.x. Use

@@ -160,32 +177,20 @@ function shortcut_set_unassign_user($account) {
+ *   Deprecated in 8.x, will be removed in 9.x. Use

@@ -198,26 +203,20 @@ function shortcut_current_displayed_set($account = NULL) {
+ *   Deprecated in 8.x, will be removed in 9.x. Use

@@ -250,42 +249,19 @@ function shortcut_set_title_exists($title) {
+ *   Deprecated in 8.x, will be removed in 9.x. Use

8.0.x, 9.0.x

jibran’s picture

I think we should add dedicated tests for API additons. What do you think @tstoeckler? Other then that this is ready.

tstoeckler’s picture

Assigned: Unassigned » tstoeckler
Status: Needs review » Needs work

Yeah, that's reasonable. Working on tests now.

tstoeckler’s picture

Assigned: tstoeckler » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
10.39 KB
18.13 KB
52.96 KB

Here we go. This fixes #111 and adds tests.

Hat tip to @tim.plunkett because after I had seen #2544746: Rewrite EntityManagerTest to use phpspec/prophecy I took this as an opportunity to learn phpspec/prophecy. Spoiler alert: It's pretty awesome!

As is often the case, I had to fix up a couple things to be able to write proper unit tests, most notably injecting the database connection in ShortcutSetStorage. I also noticed that we were missing a resetCache() override to reset the userShortcutSets member variable, that was a bug in the previous patches that is now fixed and tested.

Wim Leers’s picture

  1. +++ b/core/modules/shortcut/shortcut.module
    @@ -53,56 +55,47 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
    + *
    + * @deprecated
    + *   Deprecated in 8.0.x, will be removed in 9.0.x. Use
    + *   $shortcut_set->access('update') directly instead.
      */
     function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) {
    -  $account = \Drupal::currentUser();
    -
    -  // Shortcut administrators can edit any set.
    -  if ($account->hasPermission('administer shortcuts')) {
    -    return AccessResult::allowed()->cachePerPermissions();
    +  if (!isset($shortcut_set)) {
    +    /** @var \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage */
    +    $shortcut_set_storage = \Drupal::entityManager()->getStorage('shortcut_set');
    +    $shortcut_set = $shortcut_set_storage->getCurrentSet(\Drupal::currentUser());
       }
    -
    -  // Sufficiently-privileged users can edit their currently displayed shortcut
    -  // set, but not other sets. They must also be able to access shortcuts.
    -  $may_edit_current_shortcut_set = $account->hasPermission('customize shortcut links') && (!isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set()) && $account->hasPermission('access shortcuts');
    -  return AccessResult::allowedIf($may_edit_current_shortcut_set)->cachePerPermissions();
    +  return $shortcut_set->access('update', NULL, TRUE);
     }
    

    YAY!

  2. +++ b/core/modules/shortcut/shortcut.module
    @@ -53,56 +55,47 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
    -function shortcut_set_switch_access($account = NULL) {
    
    @@ -111,6 +104,30 @@ function shortcut_set_switch_access($account = NULL) {
    + * @deprecated
    + *   Deprecated in 8.0.x, will be removed in 9.0.x. Use
    + *   $user->access('switch_shortcut_set') with a user entity instead.
    + */
    +function shortcut_set_switch_access(AccountInterface $account = NULL) {
    +  if (!$account) {
    +    $account = \Drupal::currentUser();
    +  }
    +  /** @var \Drupal\user\UserInterface $user */
    +  $user = User::load($account->id());
    +  return $user->access('switch_shortcut_set', NULL, TRUE);
    +}
    

    YAY!

These are the main concerns I opened #2339903: Shortcut module's access checking is insane for, so marked that as a duplicate now :)

tstoeckler’s picture

I realized that I hadn't introduced tests for the newly introduced shortcut_user_access(), so I wrote that as a shiny new KernelTestBaseTNG (á la #2304461: KernelTestBaseTNG™) but then I hit #2553661: KernelTestBase fails to set up FileCache and specifically saw #2553661-12: KernelTestBase fails to set up FileCache by @alexpott:

Before we add any more KTBTNG's we need to fix https://www.drupal.org/node/2553533 - each new test added increases the chance of random fail due to test id reuse.

So not adding the new test to the patch just yet, but just providing it here as a separate patch for reference. If #2553661: KernelTestBase fails to set up FileCache lands before this I will add it to the patch (note that the overridden setUp() method is no longer necessary then, hat tip to @klausi for that by the way for that, see #2304461-252: KernelTestBaseTNG™), otherwise I will open a follow-up for the added test coverage.

This really should be ready now. Does someone feel bold enough to pull the trigger and RTBC?

jibran’s picture

Reviewing the reset of the patch as well. Here is the review of #116.

  1. +++ b/core/modules/shortcut/tests/src/Kernel/ShortcutUserAccessTest.php
    @@ -0,0 +1,104 @@
    +    $account->hasPermission('switch shortcut sets')->willReturn(TRUE);
    

    I think we need $account->hasPermission('access shortcuts')->willReturn(TRUE) as well just to make sure $user->id() == $account->id() get executed.

  2. +++ b/core/modules/shortcut/tests/src/Kernel/ShortcutUserAccessTest.php
    @@ -0,0 +1,104 @@
    +    $user = $entity_manager->getStorage('user')->create(['uid' => 1]);
    ...
    +    $account->id()->willReturn(1);
    

    Let's not check it with uid 1.

jibran’s picture

Here is the code review/suggestions. I'll review the tests later.

  1. +++ b/core/modules/shortcut/shortcut.module
    @@ -53,56 +55,47 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
    +  return $shortcut_set->access('update', NULL, TRUE);
    

    Can we pass \Drupal::currentUser() as a second param here?

  2. +++ b/core/modules/shortcut/shortcut.module
    @@ -111,6 +104,30 @@ function shortcut_set_switch_access($account = NULL) {
    +  $user = User::load($account->id());
    +  return $user->access('switch_shortcut_set', NULL, TRUE);
    

    I'd avoid calling it $user. D7 habits. We should merge both the lines.

  3. +++ b/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php
    @@ -31,7 +66,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
    +        return AccessResult::allowedIf($account->hasPermission('customize shortcut links') && $entity == $this->entityStorage->getCurrentSet($account))->cachePerPermissions()->cacheUntilEntityChanges($entity);
    

    cacheUntilEntityChanges is deprecated.

  4. +++ b/core/modules/shortcut/src/ShortcutSetStorage.php
    @@ -109,7 +127,31 @@ public function getAssignedToUser($account) {
    +      assert('$shortcut_set instanceof \Drupal\shortcut\ShortcutSetInterface');
    

    lol

  5. +++ b/core/modules/shortcut/src/ShortcutSetStorage.php
    @@ -122,14 +164,40 @@ public function getDefaultSet(AccountInterface $account) {
         $suggestions[] = 'default';
    

    Shouldn't this be $suggestions += ['default'];?

  6. ShortcutSetsTest is calling deprecated functions shortcut_default_set & shortcut_current_displayed_set.
  7. We should move AccessControlHandler to Access dir in src.
tstoeckler’s picture

#117.1: I disagree.
When testing the following code, asserting that b() will be called is sensible, but I disagree that asserting that a() is called is sensible.

if (a()) {
  b();
}

The code in question *looks* quite a lot different, but in terms of actual code flow it's the same pattern.

#117.2: This is just a unit test with a mocked user ID, so 1 has no special meaning.

#118.1 Since we were already using \Drupal::currentUser() above moved that to the top and used the result in both places.

#118.2 Well, we already have an $account variable in scope, so $user would be pretty much the only sensible choice here. Collapsing it is fine, though, so I did that.

#118.3 Fixed

#118.4 Well load() is documented as sometimes returning NULL, so...

#118.5 No += should only ever be used with keyed (= named) arrays.

$array = ['foo'];
$array += ['bar'];

yields an array with just 'foo', 'bar' is not added because both entries have the same key (0). But in this case we always want to add 'default'.

#118.6 Fixed

#118.7 In theory agree, but that would be an unnecessary API break, so I would like confirmation by a maintainer before proceeding with that change.

Status: Needs review » Needs work

The last submitted patch, 119: 2083123-119-shortcut-cleanup.patch, failed testing.

The last submitted patch, 119: 2083123-119-shortcut-cleanup.patch, failed testing.

The last submitted patch, 119: 2083123-119-shortcut-cleanup.patch, failed testing.

jibran’s picture

All of my feedback got addressed or reasoned with so this is ready imo. We just need a green patch. Can we add KTBNG tests from #116 now?

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
1.27 KB
63.25 KB

This should fix it.

Re #123: The patch in #119 already included the test.

Status: Needs review » Needs work

The last submitted patch, 124: 2083123-119-shortcut-cleanup.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
636.29 KB

Interdiff was correct, but I rolled the wrong patch.

tstoeckler’s picture

FileSize
62.97 KB

#fail

The last submitted patch, 126: 2083123-126-shortcut-cleanup.patch, failed testing.

jibran’s picture

Let's add a change notice for deprecated methods and then we are good to go.

tstoeckler’s picture

Issue summary: View changes

Added a draft change notice.

The last submitted patch, 124: 2083123-119-shortcut-cleanup.patch, failed testing.

The last submitted patch, 126: 2083123-126-shortcut-cleanup.patch, failed testing.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

I pinged @berdir(for methods added to entity classes) and @larowlan(to eyeball the tests) for the review in IRC. Other then that this is RTBC.

larowlan’s picture

+++ b/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php
@@ -10,14 +10,49 @@
+use Drupal\node\Plugin\views\filter\Access;

unintended changed?

Can be fixed on commit.

Great work @tstoeckler and @jibran

tstoeckler’s picture

Lol, yeah, sorry about that. In case of re-roll will remove but leaving at RTBC for now. Thanks for the review!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Shortcut cleanup:

  • Fix bug during config import
  • remove duplicated code
  • deprecate legacy functions

Can this be split out into three issues please - makes it easier to review and way less risky.

jibran’s picture

Title: Shortcut cleanup: Fix bug during config import, remove duplicated code, deprecate legacy functions » Shortcut cleanup: Remove duplicated code and deprecate legacy functions
Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Needs review
FileSize
62.84 KB

Fix bug during config import

Created #2641182: Fix the config import bug in Shortcut for this.
Changed the scope of the issue to Remove duplicated code and deprecate legacy functions.
Rerolling the #127 for 8.1.x now. We can extract #2641182: Fix the config import bug in Shortcut bits later.

Status: Needs review » Needs work

The last submitted patch, 137: shortcut_cleanup_fix-2083123-137-8.1.x.patch, failed testing.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Patch no longer applies, which isn't as bad as you'd think, since that gives us a moment to re-think. :-)

Refactored some top-level functions into a module-scoped service here: #2731591: Move shortcut.module to 'shortcut.module' service

This gives us a replacement for these functions when we deprecate them.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tstoeckler’s picture

Issue tags: +Dublin2016

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

This came up again, this time in #2914110: Shortcut hook_toolbar implementation makes all pages uncacheable. It'd be great if this could move forward again! I can provide reviews.

andypost’s picture

Issue tags: +Needs reroll
savkaviktor16@gmail.com’s picture

Took that

savkaviktor16@gmail.com’s picture

re-rolled

Status: Needs review » Needs work

The last submitted patch, 150: shortcut_cleanup_fix-2083123-150.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ndobromirov’s picture

Patch in #150 changes line indentation from spaces to tabs - needs another re-roll to fix that.
I have not tested anything else.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

claudiu.cristea’s picture

As this issue removes the usage of drupal_static() & drupal_static_reset() from the shortcut.module, I'm adding this as child of #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()

slv_’s picture

Hi \o. I'm working on a contrib version of the module that allows users to maintain their own shortcut sets, using content entities for shortcut sets as well, instead of config entities. I'll post a link to the module once it's up and ready.

slv_’s picture

Sandbox for a content-entity-based module for user shortcuts: https://www.drupal.org/sandbox/slv/3072644. I'll be promoting to full project in a couple days, after some review, clean up of classes, CS fixes, etc. Assuming core wants to do a similar thing, I guess it could be usable as a base.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Wim Leers’s picture

I'd still love to see this happen 🤞

jibran’s picture

Reroll of #137.
@Wim Leers care to reveiw?

Status: Needs review » Needs work

The last submitted patch, 160: 2083123-160.patch, failed testing. View results

jibran’s picture

Also, any pointers on one last remaining fail in JSONAPI test would be appricated @Wim Leers. :)

andypost’s picture

Version: 8.9.x-dev » 9.1.x-dev
hash6’s picture

Assigned: Unassigned » hash6
ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
62.85 KB

Rerolling patch for 9.1.x

ridhimaabrol24’s picture

Assigned: hash6 » Unassigned
ridhimaabrol24’s picture

Fixing PHP lint error in #165.

Status: Needs review » Needs work

The last submitted patch, 167: 2083123-167.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
62.81 KB
2.17 KB

Fixing testcases!

Status: Needs review » Needs work

The last submitted patch, 169: 2083123-169.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
64.2 KB
1.39 KB

Fixing test cases!

Status: Needs review » Needs work

The last submitted patch, 171: 2083123-171.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

sanjayk’s picture

Re-roll for 9.2

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
63.15 KB
2.83 KB

Fixed CS issues.

Status: Needs review » Needs work

The last submitted patch, 175: 2083123-175.patch, failed testing. View results

vsujeetkumar’s picture

Status: Needs work » Needs review
FileSize
64.1 KB
3.1 KB

Fixing Tests.

Status: Needs review » Needs work

The last submitted patch, 177: 2083123-177.patch, failed testing. View results

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

+++ b/core/modules/shortcut/shortcut.module
@@ -54,60 +55,50 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.

@@ -115,6 +106,29 @@ function shortcut_set_switch_access($account = NULL) {
+ * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.

@@ -126,32 +140,20 @@ function shortcut_set_switch_access($account = NULL) {
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.

@@ -164,26 +166,20 @@ function shortcut_current_displayed_set($account = NULL) {
+ * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.

@@ -195,42 +191,20 @@ function shortcut_default_set($account = NULL) {
+ * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.

all deprecations needs update to 9.3.0 and 10.0.0

vsujeetkumar’s picture

Status: Needs work » Needs review
FileSize
64.05 KB

Re-roll patch created for 9.3.x.

longwave’s picture

Status: Needs review » Needs work
FILE: /var/www/html/core/modules/shortcut/src/Entity/ShortcutSet.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
 69 | ERROR | Parameter $update is not described in comment
 74 | ERROR | Expected type hint "ShortcutSetStorageInterface"; found
    |       | "EntityStorageInterface" for $storage
 93 | ERROR | Parameter $entities is not described in comment
 98 | ERROR | Expected type hint "ShortcutSetStorageInterface"; found
    |       | "EntityStorageInterface" for $storage
----------------------------------------------------------------------
vsujeetkumar’s picture

Status: Needs work » Needs review
FileSize
64.25 KB
1.04 KB

Fixed issues mentioned in #182. Please have a look.

Status: Needs review » Needs work

The last submitted patch, 183: 2083123-183.patch, failed testing. View results

vsujeetkumar’s picture

Worked on #180, Please have a look.

vsujeetkumar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 185: 2083123-185.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

manuel.adan’s picture

Category: Bug report » Task
Issue summary: View changes
Status: Needs work » Needs review
FileSize
63.46 KB
6.4 KB

I've done a general review of the patch, making the following changes:

  • got back checking for shortcut link theme settings prior to set the add/remove link that seems to be removed
  • updated "deprecated in" directives from drupal:9.3.0 to 9.4.0
  • removed setUp in ShortcutUserAccessTest, it seems to be no longer necessary
  • fixes some comments, minor CS review

Category moved to task, D8 beta phase is over by far ;)

Status: Needs review » Needs work

The last submitted patch, 189: 2083123-189.patch, failed testing. View results

manuel.adan’s picture

Status: Needs work » Needs review
FileSize
65.77 KB
2.08 KB

Tests have been failing due to cache tags differences since #160, may be even before. After some investigation, I found that it failed when the user permissions changes during a same test run, what seemed to be related to control access handler cache resetting.

The new shortcut access control handler relies on the shortcut set one, so cache resetting on the first one must reset the other as well.

Status: Needs review » Needs work

The last submitted patch, 191: 2083123-191.patch, failed testing. View results

manuel.adan’s picture

Backs ShortcutTranslationUITest cache contexts declaration to its original state and fixing the test group declaration that makes it to be skipped while targeting shortcut only tests in my local machine.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

The last submitted patch, 195: 2083123-195.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
FileSize
66.58 KB

Uploaded the wrong patch sorry!

Status: Needs review » Needs work

The last submitted patch, 197: 2083123-197.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
FileSize
1.75 KB
65.54 KB

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
145 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wim Leers’s picture