Needs work
Project:
Shortcut (from core)
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Mar 2015 at 21:22 UTC
Updated:
16 Aug 2026 at 16:56 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerInteresting!
Comment #2
tstoecklerComment #3
kgoel commentedComment #4
tstoecklerOops, thanks!
Also assigning to me for now.
Comment #5
tstoecklerHere we go. This was ridiculously easy (but for the test failures...) because we're at a point where Entity API Just Works© (yay!).
This should be green already. Note that I had quite some fails at first and even found an separate core bug (will open issue in a minute) so that does not mean that test coverage is insufficient.
I snuck in a few changes that could be left out, but make sense to do as part of this:
- Add
AccountInterfacetypehinting to some ShortcutStorageInterface methods. This is not an API change it's only documenting what happens anyway. What we really want isUserInterfacebut that would be an API change, which is why I'm doing that magic loading dance.- Fix some test assertions to be more debuggable.
Next step is ripping out the custom form stuff for assigning a shortcut set to a user. Current plan is to introduce a new form mode for that, we'll see how that goes.
Comment #7
tstoecklerHehe, good thing we have the testbot. I only ran the shortcut tests locally, and then obviously my two favorite tests in the world get jealous and want to spend some alone time with me. Fun!
Comment #8
tstoecklerLet's see if this is green.
ModuleInstallUninstallTestrevealed that the schema updates were not being applied on install and uninstall of the module. I thought that was a weirdness of the test, which is why I added it into some of the tests above, but it was in fact not working. In my local testing I just used Standard profile which does that manually instandard_install()(which is super weird, by the way!).This fixes that, so could be green.
It reveals another problem, however: With this patch shortcut module cannot be uninstalled as soon as any user has ever submitted the switch shortcut sets form. That's kind of a good thing, as that means the entity API correctly detects that it's going to delete unrecoverable data and it refuses to do that (which is nice), but it's not really an acceptable situation. Not sure what the fix for that is exactly, but we somehow need to handle the
defaultshortcut set differently, I think.Comment #9
dawehnerThe patch looks really great!!
One thing I just don't get, when does someone uses a base field, and when does someone uses a configurable field? Do you always uses base fields if you are in code?
This is much nicer!
Comment #10
tstoecklerThanks!
Yes, basically that is it. As soon as there is business logic (i.e. code) that requires that field it makes sense to use a base field.
Also: isn't it just way more fancy that writing/exporting a bunch of YAML files? ;-)
I agree. :-) I think with this
ShortcutSetStorageInterfaceis basically obsolete, I did not add@todos yet to remove the relevant methods (in 9.x). At the very leastassignUser,unassignUserandgetAssignedToUserare rather silly with the patch.Comment #11
jibranWe just need a change record here and we are good to go.
Code changes make a lot of sense and if we can fix #2083123: Shortcut cleanup: Remove duplicated code and deprecate legacy functions it'd be perfect.
Also, adding it as a base field and not as configureable is a very good idea.
Comment #12
waringnick commentedChange record available here: https://www.drupal.org/node/2447781
Let me know if anything needs to be added
Comment #13
tstoecklerThanks for the change record @waringnick! I added some example code to it.
I think the patch is in fact ready to go. Attached patch just adds some
@todos to the methods mentioned in #10.I spent a lot of time thinking about and hacking around the "problem" described in #8 until I realized that I am an incredible buffoon and there is absolutely no problem at all. Shortcut module cannot be uninstalled if there are shortcut entities (with and without the patch), this has nothing at all to do with the user->shortcut_set assignments.
I also had a stab at making the switch shortcut set form a proper (user) entity form that uses widgets for the shortcut set reference fields. Even though that would be the correct implementation in theory there are several nitty gritty details that made me revert all those nice local commits in the end:
setDisplayOptions()only apply to the default form mode. Any additional form modes have to specified as an entity form display entity in YAML which inevitably makes them appear in the UI, which might not be what we want.Drupal\Core) but that does not have theauto_createfeature that the current form has, where you can create a new shortcut set on the fly. So that would have to be added somehowOptionsWidgetBasebecause that hardcodes the plugin IDs of its subclasses ingetOptions(). While that is a legitimate bug in its own right, it would be out of scope to fix here.In summary, in order to make the form an entity form we would have to code around too many shortcomings of our APIs to even remotely justify the benefit.
Played around with it again and everything seems to work.
Comment #14
tstoecklerHmm... apparently I got our standards for documenting
@deprecatedcode wrong. This one should be better.Comment #16
tstoecklerSorry for the noise.
Interdiff was correct, here's the patch I should have posted in #14.
Comment #17
jibranGiven that it's not disruptive and a huge architectural win I think It would be awesome if we can commit it and make shortcut module more maintainable. Thanks @tstoeckler for the patch and issue.
Comment #18
berdirWell, it *is* disruptive to existing installations ;)
Comment #19
berdirAlso, do we have any tests that uninstall shortcut.module when there have been user assignments? You can't just run applyUpdates() in hook_uninstall, I can't imagine that being enough. We would need to use the API to remove the field first, and make sure we delete the data, which AFAIK isn't actually possible yet? (the field purge process).
Comment #20
tstoecklerRe #18: That hasn't been a criterion before (e.g. user_roles and other things), which is why I pursued this in the first place. You are of course correct, though.
Re #19: Will test again. I think I verified that this worked, but will re-verify. Setting to "needs review" for that.
Comment #21
tstoecklerThis does in fact not work correctly, thanks @Berdir. Will post updates later.
Comment #22
tstoecklerSo at the time
hook_uninstall()gets called the respective module (Shortcut in this case) is still registered as installed and still takes part in hooks, etc. That's why the call toEntityDefinitionUpdateManager::applyUpdate()doesn't work: Because at the time of calling the field storage definition for theshortcut_setfield still exists.What does work, though, is removing the field storage definition "manually" á la:
There is no field purging involved. The uninstallation is only possible if no data is stored in the field in the first place and the
onFieldStorageDefinitionDelete()simply drops the column alltogether, which is exactly what we want.The problem that crops up then, is that when Shortcut module is uninstalled the
defaultshortcut set along with any other shortcut sets, which aren't used anymore is deleted. SoShortcutSetStorage::deleteAssignedUsers()is called which queries theshortcut_setfield on users, which doesn't exist anymore at that point.I haven't found a solution to that yet, so no new patch.
Thanks again @Berdir, for pointing this out!!!
Comment #23
tstoecklerNot necessarily advocating this as a good idea, but let's see if this is green at least.
(Note that I need to use
getLastInstalledFieldStorageDefinition()because the storage definition does not exist at that point anymore. Seems awkward at first, but I think (?) it's kind of correct.)As @Berdir pointed out, this points to a more general problem of uninstalling modules which provide field storage definitions for other entity types. Trying to uninstall Content Translation will be equally borked, if not more.
Comment #24
tstoecklerActually, writing #23 I realized that makes
EntityDefinitionUpdateManager::applyUpdates()which does make me slightly less uneasy about this approach.Comment #26
tstoecklerMaybe it was right there all along. If this is green, I want a cookie.
Comment #29
tstoecklerI meant to revert that
post_uninstallstuff before, which this does. Also took a stab at fixing KernelTestBase. I have a strange batch error locally, but am hoping that's not reproducible.Comment #30
tstoecklerComment #32
tstoecklerSorry
(interdiff is correct...)
Comment #34
tstoecklerOk, if this still doesn't apply, I seriously have to consider just quitting IT and becoming a construction worker or something...
Comment #35
tstoecklerAwesome, so that seems to have worked.
I think these latest changes revealed on a major bug I would title "Modules that provide dynamic field storages cannot be uninstalled reliably" that should be split and fixed separately, but @Berdir rightly pointed out that @plach should have a look at the patch so I wanted to wait for that before doing any issue queue foo.
Assigning for that purpose and will try to reach out in IRC.
Comment #36
tstoecklerWe can save some characters after #2449709: ContentEntityBase::set() does not respect its interface went in.
Comment #38
tstoecklerHmm... random?
Comment #39
jibranNice it's green. Now can we please move all the non shortcut module stuff to a separate issue and postpone till that's committed? Because this is a task and we identified a bug. Is it worth adding tests for #19?
Comment #40
plachI don't think this is correct: applying updates can do way more than simply notifying entity type creation/deletion, so it might easily mean we end-up applying unrelated changes without the user being aware of that.
I opened #2346013: Improve DX of manually applying entity/field storage definition updates some time ago to make sure we are able to limit applied updates to a single module, which would be definitely more correct here. Still I'm not sure it would be the right solution.
Not sure why this is needed, but I suspect it's telling us there's something wrong elsewhere. If it's just about removing lingering base field schema, we have #2282119: Make the Entity Field API handle field purging for that.
Comment #41
tstoecklerYes, that was the reason I started all this in the first place. I will move the relevant code as proposal to the issue(s) you linked and re-focus the patch here. Should be a lot less controversial then. Thanks!
Comment #44
jibranbump
Comment #45
mgiffordUnassigning stale issue. Hopefully someone else will pursue this.
Comment #46
jibranComment #61
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #62
smustgrave commentedWith shortcut being deprecated will let the new maintainer decide this one.
Comment #64
smustgrave commented