Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Updated: Comment #108
Problem/Motivation
There are several problems in shortcut.module
:
shortcut_current_displayed_set
,shortcut_default_set()
, andShortcutSetStorage::getDefaultSet()
can returnNULL
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.)- 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
- There is duplicated code between
shortcut.module
andShortcutSetStorage
/shortcut_default_set()
<=>ShortcutSetStorage::getDefaultSet()
andshortcut_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
- Deprecate
shortcut_set_edit_access()
in favor of$shortcut_set->access('update')
- Deprecate
shortcut_set_switch_access()
in favor of$user->access('switch_shortcut_set')
which calls out to a newhook_user_access()
implementation in Shortcut module (API addition) - Deprecate
shortcut_current_displayed_set()
in favor of a newShortcutSetStorage::getCurrentSet()
(API addition) - Deprecate
shortcut_default_set()
in favor ofShortcutSetStorage::getDefaultSet()
. The latter is also fixed to always return a shortcut set. (Bug fix) - Deprecate
shortcut_renderable_links()
in favor of a new$shortcut_set->getRenderableShortcuts()
(API addition) - 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. - 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
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. |
Comment | File | Size | Author |
---|---|---|---|
#201 | 2083123-nr-bot.txt | 145 bytes | needs-review-queue-bot |
#199 | 2083123-199.patch | 65.54 KB | smustgrave |
#199 | interdiff-197-199.txt | 1.75 KB | smustgrave |
#183 | 2083123-183.patch | 64.25 KB | vsujeetkumar |
#181 | 2083123-181.patch | 64.05 KB | vsujeetkumar |
Comments
Comment #1
e0ipsoFirst 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.
Comment #2
e0ipsoComment #3
RoSk0Comment #4
jibranI think we should complete following things in this issue.
ShortcutManager
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
shortcut_set_edit_access
now we haveShortcutSetEditAccessCheck
shortcut_set_switch_access
now we haveShortcutSetSwitchAccessCheck
shortcut_link_access
now we haveLinkAccessCheck
ShortcutManager
to all shortcutAccessControllers
which are using above methodsShortcutManager
to all shortcutControllers
which are using above methodsShortcutManagerInterface
.(needs discussion)ShortcutSetAccessController
toDrupal\shortcut\Access
namespace. (optional)csrf_token
service toShortcutSetController
and replace call to drupal_valid_token. (optional)Comment #5
tim.plunkettshortcut_set_load should be removed, no reason for to to exist
Comment #6
e0ipso@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.
Comment #7
dawehnerCrosslinking: #2021779: Decouple shortcuts from menu links
Comment #8
jibranThank you @e0ipso for working on this.
Here is the minor review.
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
So all the public methods of a manager will go to interface.
Comment #9
larowlanFirst up - great job!
Can we type hint on the interface
Can we inject the shortcut storage controller (may need to inject entity.manager and then store the shortcut storage controller on the object)
Can this be injected?
We can implement ContainerFactoryPluginInterface and inject the shortcut manager
book => shortcut
Missing type
Should this be a public static property on the object instead?
We can inject this from the services.yml file
We have the storage controller, we should use it to load.
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.
Missing type (bool)
missing public|private
Can we use the load by properties method, passing the title instead of loading them all?
Url::isExternal($path); instead of url_is_external()
> 80 chars
We have the entityManager, we can use it to get the storage controller for menu links and call ::create on that.
objects are always passed as reference - do we need the & in the function signature any more?
Missing type (array)
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?
The function signature doesn't contain a type-hint to match this
Missing type (bool)
Can we inject this?
Is it just an object? Or is it an AccountInterface? or perhaps a UserInterface?. Same story in function signature.
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.
Whitespace
We can inject the shortcut manager by implementing ContainerInjectionInterface.
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.
This needs to be retained as just a wrapper to the service and marked @deprecated
Out of scope?
Finally can we get a follow-up to add some phpunit tests for the manager?
Comment #10
e0ipso@larowlan thank you for your comments. I implemented your suggestions, but I have some comments about 27.
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
because is not used anywhere in the current 8.x branch and polluted unnecessarily the manager.
Tests turned green in my local.
Comment #11
e0ipso@larowlan thank you for your comments. I implemented your suggestions, but I have some comments about 27.
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.
Comment #12
jibranThanks @larowlan for the detailed review. once again great work by @e0ipso.
Here are some minor issues.
need better doc.
What is narrower scope? I still think we should inject current_user service.
We can use
$this->defaultSet()
here.moduleHandler Injection
use complete namespace.
Typehint missing.
whitespace.
Comment #13
e0ipsoOoops, there were some changes pending to commit.
Comment #15
e0ipsoAdding 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 tocore.services.yml
you'll see that thecurrent_user
service hasscope: 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
.Comment #16
e0ipsoComment #17
e0ipsoRead #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 thecurrent_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.Comment #19
jibran#15: shortcut-create-shortcut-manager-2083123-14.patch queued for re-testing.
Comment #21
larowlanobject
Yeah we've seen issues with the current_user service on other issues.
Comment #22
andypostRelated bug in simpletest #2102539: Current user service should be updated in drupalLogin() and drupalLogout()
Comment #23
jibranReroll and fixes for #21.
Comment #25
e0ipsoReworking this to (hopefully) get it back to green.
Comment #26
e0ipsoComment #27
jibranYay!! 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.Comment #27.0
jibranUpdated issue summary.
Comment #28
jibran25: shortcut-create-shortcut-manager-2083123-25.patch queued for re-testing.
Comment #30
e0ipsoRerolled #25.
Comment #33
jibran30: shortcut-create-shortcut-manager-2083123-30.patch queued for re-testing.
Comment #35
e0ipsoComment #36
jibranReroll.
Comment #37
jibranSome fixes
Comment #38
andypostImplemenation of
shortcutSetEditAccess()
andshortcutSetSwitchAccess()
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 overridablesuppose this function should live in controller where used
same
Suppose better leave this ones as access controllers
Better to file new issue to get rid of shortcut_set_load()
Comment #39
andypostFiled #2161371: Deprecate shortcut_set_load() in favour of entity_load()
Comment #40
larowlanMissing short description.
Should typehint ModuleHandlerInterface, AliasManagerInterface, RouteProviderInterface and EntityManagerInterface?
should use a static class property?
and
Do we still support menu_get_item()? pretty sure there's an effort to remove that.
would this be better off to just use reset() to load the first item from the suggestions?
Short description > 80 chars.
%s/ShortcutManager/ShortcutManagerInterface
Should this be saving menu_link entities now? I thought shortcut entities were decoupled form menu_links? If so, we are missing test coverage.
This would seem to confirm my suspicions that the entity type should be shortcut and not menu_link
>80 chars
this->t()?
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)
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?
Comment #41
ParisLiakos CreditAttribution: ParisLiakos commentedComment #44
tstoecklerSo because we don't actually remove the functions here but only deprecate them the only API changes are:
into the
Access
sub-namespaceto 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.
Comment #45
tstoecklerDidn't get all the way through, but here goes:
As mentioned above let's revert this.
"The shortcut manager" would be more standard I think.
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 getShortcutSetAccessController
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')
Comment #46
kgoel CreditAttribution: kgoel commentedworking on this
Comment #47
kgoel CreditAttribution: kgoel commentedThis 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 :)
Comment #48
kgoel CreditAttribution: kgoel commentedIt's interesting that PhpStorm reformatting doesn't add new line at the EOF.
Comment #49
kgoel CreditAttribution: kgoel commentedI am an idiot - moved shortcut.services.yml to src folder :(
Comment #50
kgoel CreditAttribution: kgoel commentedWIP patch
Comment #51
kgoel CreditAttribution: kgoel commentedstill WIP
Comment #52
kgoel CreditAttribution: kgoel commentedWIP
Comment #53
kgoel CreditAttribution: kgoel commentedComment #54
kgoel CreditAttribution: kgoel commentedComment #55
kgoel CreditAttribution: kgoel commentedComment #57
kgoel CreditAttribution: kgoel commentedComment #59
jibranVery nice work @kgoel. Let's add some phpunit tests for ShortcutManager as well.
Let's revert this change.
Why do we have $account and $user both here?
I'm sure we can add some property in ShortcutManger and unset it here.
Comment #60
kgoel CreditAttribution: kgoel commented@jibran thanks for the review.
I am not sure about this. please see shortcutSetEditAccess?
Fixed
Can you please be specific?
hopefully this patch will fix some fails.
Comment #62
kgoel CreditAttribution: kgoel commentedComment #64
kgoel CreditAttribution: kgoel commentedComment #66
kerby70 CreditAttribution: kerby70 commentedCorrecting non standard tag 'Need tests' to 'Needs tests'
Comment #69
XanoRe-roll.
I'm already working on another version of the patch to fix a few more things.
Comment #70
jibranI know @tstoeckler has posted a very convincing reason in #44 but let's get a proper approval first from any core committer.
Comment #72
XanoOne 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.Comment #74
XanoComment #75
kgoel CreditAttribution: kgoel commentedIts 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).
Comment #76
XanoWhich 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.
Comment #77
kgoel CreditAttribution: kgoel commentedI was talking about this class but correct me if I am wrong.
Comment #78
XanoAh 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.Comment #79
kgoel CreditAttribution: kgoel commentedwhy 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?
Comment #80
XanoA
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.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.
Comment #81
kgoel CreditAttribution: kgoel commentedI 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.
Comment #82
cilefen CreditAttribution: cilefen commentedThis needs a beta evaluation. Shouldn't the old functions be marked deprecated in this issue or in a follow-up issue?
Comment #83
Crell CreditAttribution: Crell at Palantir.net commentedI wouldn't view a constructor as part of an API by default. Only if specifically called out as such.
Comment #84
tstoecklerIn addition to the below the current patch is still work in progress, so undoubtedly "needs work".
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.
It seems both of these are unnecessary dependencies, or am I missing something?
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.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 ontoShortcutSetInterface
instead.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 inShortcutSetAccessControllerHandler::checkAccess()
. Then the current methods can look likeThe specified variable doesn't actually exist. More importantly,
drupal_static_reset()
(by design) does not work with class variables. We could add areset()
method toShortcutManager
that does this, but that would still mask the larger problem IMO: We have circular dependency here, betweenShortcutManager
andShortcutSetStorage
.ShortcutManager
callsShortcutSetStorage
to load the assigned shortcut set andShortcuSetStorage
wants to reset the static inShortcutManager
when a new assignment is made. We should fix that properly. I see two possible ways out:ShortcutManager::currentDisplayedSet()
intoShortcutSetStorage
assignUser()
method toShortcutManager
which proxies to the same method inShortcutSetStorage
and resets its own storage.I prefer the second option because that keeps
ShortcutSetStorage
strictly about storage.Comment #85
tstoecklerTaking a stab at this
Comment #86
tstoecklerHere 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 theassignUser()
andunassignUser()
methods alltogether so if you're not too fond of them now (additionally) living onShortcutManager
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.
Comment #88
tstoecklerSorry.
Comment #90
tstoecklerThese should pass TRUE as the third parameter.
Will fix in a minute.
(Sorry for the d.o debugging... :-/)
Comment #91
tstoecklerNext try.
Comment #93
tstoecklerSo the very rare condition that
ShortcutManager::getDefaultSet()
returnNULL
does actually happen. This was just masked by coincidence (and lack of docs) before. In fixing this I foundShortcutSetStorage::getDefaultSet()
which was introduced way back in #1978976: Convert shortcut_set_switch to a Controller. It is a direct copy ofshortcut_default_set()
nowShortcutManager::getDefaultSet()
. In other words, the latter is completely unnecessary. So since theassignUser()
/unassignUser()
methods are really just proxies, the only "real" method left onShortcutManager
isgetCurrentSet()
. 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 forShortcutSetStorage
in the first place. Will try that out now....and also make
ShortcutManager::getDefaultSet()
always return a shortcut set.Comment #94
jibranAwesome work @tstoeckler. I think after the green patch and a unit test for ShortcutManager we'll be ready.
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.
Comment #95
tstoecklerHere 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.
Comment #97
jibranThis 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.
$user will always be set.
getRenderableLinks
seems little misplaced. If we'll rename it togetRenderableShortcutLinks
orgetRenderableShortcuts
. I thinkgetRenderableShortcuts
is much better as we already havegetShortcuts
.No shortcut manger anymore.
How about "Returns a renderable array of shortcut links for this shortcut set"?
This makes ton of sense.
one space too many.
Comment #98
tstoecklerComment #99
tstoecklerThanks for the review, #98 should address it, and hopefully fix the tests. I also rolled in the fix for #94.
Comment #101
tstoecklerWill try to tackle the test fails, but this no longer needs to be assigned to me.
Comment #102
willzyx CreditAttribution: willzyx commentedshould be
$this->shortcutSetStorage = $entity_manager->getStorage('shortcut_set');
With this fix the tests should pass
Comment #103
willzyx CreditAttribution: willzyx commentedComment #105
willzyx CreditAttribution: willzyx commentedAdded check for the very rare case that Shortcut module has been enabled but its configuration has not yet been installed.
Comment #106
dawehnerWeb services != services
Comment #107
tstoecklerI 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 togetDefaultSet()
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 aNULL
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.
Comment #109
tstoecklerUpdated 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.Comment #110
tstoecklerThis should be green.
Comment #111
tim.plunkett8.0.x, 9.0.x
Comment #112
jibranI think we should add dedicated tests for API additons. What do you think @tstoeckler? Other then that this is ready.
Comment #113
tstoecklerYeah, that's reasonable. Working on tests now.
Comment #114
tstoecklerHere 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 aresetCache()
override to reset theuserShortcutSets
member variable, that was a bug in the previous patches that is now fixed and tested.Comment #115
Wim LeersYAY!
YAY!
These are the main concerns I opened #2339903: Shortcut module's access checking is insane for, so marked that as a duplicate now :)
Comment #116
tstoecklerI 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: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?
Comment #117
jibranReviewing the reset of the patch as well. Here is the review of #116.
I think we need
$account->hasPermission('access shortcuts')->willReturn(TRUE)
as well just to make sure$user->id() == $account->id()
get executed.Let's not check it with uid 1.
Comment #118
jibranHere is the code review/suggestions. I'll review the tests later.
Can we pass
\Drupal::currentUser()
as a second param here?I'd avoid calling it
$user
. D7 habits. We should merge both the lines.cacheUntilEntityChanges
is deprecated.lol
Shouldn't this be $suggestions += ['default'];?
shortcut_default_set
&shortcut_current_displayed_set
.AccessControlHandler
to Access dir in src.Comment #119
tstoeckler#117.1: I disagree.
When testing the following code, asserting that
b()
will be called is sensible, but I disagree that asserting thata()
is called is sensible.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 returningNULL
, so...#118.5 No
+=
should only ever be used with keyed (= named) arrays.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.
Comment #123
jibranAll 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?
Comment #124
tstoecklerThis should fix it.
Re #123: The patch in #119 already included the test.
Comment #126
tstoecklerInterdiff was correct, but I rolled the wrong patch.
Comment #127
tstoeckler#fail
Comment #129
jibranLet's add a change notice for deprecated methods and then we are good to go.
Comment #130
tstoecklerAdded a draft change notice.
Comment #133
jibranI 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.
Comment #134
larowlanunintended changed?
Can be fixed on commit.
Great work @tstoeckler and @jibran
Comment #135
tstoecklerLol, yeah, sorry about that. In case of re-roll will remove but leaving at RTBC for now. Thanks for the review!
Comment #136
alexpottShortcut cleanup:
Can this be split out into three issues please - makes it easier to review and way less risky.
Comment #137
jibranCreated #2641182: Fix the config import bug in Shortcut for this.
Changed the scope of the issue to .
Rerolling the #127 for 8.1.x now. We can extract #2641182: Fix the config import bug in Shortcut bits later.
Comment #140
Mile23Patch 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.
Comment #142
tstoecklerComment #144
Wim LeersThis also just came up in #2843750-34: EntityResource: Provide comprehensive test coverage for Shortcut entity.
Comment #147
Wim LeersThis 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.
Comment #148
andypostComment #149
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedTook that
Comment #150
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commentedre-rolled
Comment #152
ndobromirov CreditAttribution: ndobromirov at FFW commentedPatch in #150 changes line indentation from spaces to tabs - needs another re-roll to fix that.
I have not tested anything else.
Comment #155
claudiu.cristeaAs 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()Comment #156
slv_ CreditAttribution: slv_ at Lullabot for NBCUniversal commentedHi \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.
Comment #157
slv_ CreditAttribution: slv_ at Lullabot for NBCUniversal commentedSandbox 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.
Comment #159
Wim LeersI'd still love to see this happen 🤞
Comment #160
jibranReroll of #137.
@Wim Leers care to reveiw?
Comment #162
jibranAlso, any pointers on one last remaining fail in JSONAPI test would be appricated @Wim Leers. :)
Comment #163
andypostComment #164
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedComment #165
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedRerolling patch for 9.1.x
Comment #166
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedComment #167
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing PHP lint error in #165.
Comment #169
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing testcases!
Comment #171
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing test cases!
Comment #174
sanjayk CreditAttribution: sanjayk as a volunteer and commentedRe-roll for 9.2
Comment #175
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedFixed CS issues.
Comment #177
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedFixing Tests.
Comment #180
andypostall deprecations needs update to 9.3.0 and 10.0.0
Comment #181
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedRe-roll patch created for 9.3.x.
Comment #182
longwaveComment #183
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedFixed issues mentioned in #182. Please have a look.
Comment #185
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedWorked on #180, Please have a look.
Comment #186
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedComment #189
manuel.adanI've done a general review of the patch, making the following changes:
Category moved to task, D8 beta phase is over by far ;)
Comment #191
manuel.adanTests 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.
Comment #193
manuel.adanBacks 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.
Comment #195
smustgrave CreditAttribution: smustgrave at Mobomo commentedRerolled for 9.5.x
Comment #197
smustgrave CreditAttribution: smustgrave at Mobomo commentedUploaded the wrong patch sorry!
Comment #199
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #201
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe 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.
Comment #203
Wim Leers#3427046: Shortcuts toolbar links are not updated automatically when default shortcut set is changed landed and AFAICT has solved some of the problems that this issue was aiming to solve 😊