Closed (fixed)
Project:
Content locking (anti-concurrent editing)
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Oct 2017 at 10:20 UTC
Updated:
21 Nov 2017 at 21:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tstoecklerThis implements the suggested approach. I originally wanted to make the behavior configurable in some way, but since the behavior ended up being fairly complex on its own, I did not implement this yet so as not to increase the complexity further. Would love some thoughts on whether some way of configurability will be needed and if so, how we should go about that.
Part of the complexity stems from the fact that it is unnecessarily difficult to disable a form in an Ajax request, I will open a core issue to discuss and possibly improve that.
I tried to document all the weird bits in code, so not repeating that here, but would obviously love any input on how to improve the patch and possibly remove some of the weirdness.
Comment #4
tstoecklerSorry, this one should apply properly.
Comment #5
tstoecklerGrrrr
Comment #7
tstoecklerI realized that rebuilding the form during the Ajax submission somewhat defeats the purpose of Prefetch Cache in the first place. So this one just modifies the form on the fly and sends it back directly. It's a bit less elegant IMO, but should be a lot quicker, especially for bigger forms.
Comment #9
kfritscheThe approach by tstoeckler still has problems when using modules like prefetch_cache, as on the first ajax request the hole form is rebuild anyway. And this is then the first ajax request.
There is an open issue for this #2851251: Forms look at current request method rather than form method for cache check. This breaks AJAX forms because every first visit is GET.
Till then we decided to switch to our own JS/Ajax implementation and not using form API ajax here. This is much faster.
Also new patch includes setting to disable/enable this.
No interdiff as its a different approach and first patch wasn't used at all :/
fyi: we have an experimental branch open on github (https://github.com/attrib/content_lock) which merges the latests patches by hchonov, tstoeckler and me.
Comment #11
chr.fritschThank you @biologis guys for all the recent contributions. If you could get the test pass and the issues RTBC i am very grateful for all your improvments.
Comment #12
kfritscheThis should fix the current tests.
New tests would be nice, but not sure if I get to it soon :/
Comment #13
hchonovIt looks good. Thank you! Unfortunately, I have a couple of remarks :)
According to the jQuery documentation when setting "disabled" we should use the jQuery prop method instead the attr method.
I think this is not really needed :)
Let's add the renderer service through "dependency injection" :).
The $request parameter is not used, therefore it should be removed. If it is not present in the method definition then Drupal will not pass it. @see https://www.drupal.org/docs/8/api/routing-system/using-parameters-in-routes
-> Not lockable entity or entity creation. :)
If there are multiple forms on which the content lock is enabled, then regardless of the form for which the lock is being broken the user will always be redirected to the edit-form, instead to the form on which she currently is. We have to find a way to redirect the user to the proper destination.
Could we probably add a specific class to the actions in hook_form_alter and use this class as a selector instead of relying on the element ID being '#edit-actions'?
Comment #14
hchonovJust nits :
We have to add the new lines.
Comment #15
kfritscheThanks for the review. I hope I fixed now all the issues.
4. is not fixed as its now used for 6. :)
Good catch. I add now a destination query when generating the ajax lock url, which then is used here if given. edit-form is now the fallback, if somehow no destination is given.
Regarding new lines, fixed my PHPStorm settings :/
Comment #16
hchonovRegarding 1. - I've missed that there are two lines where disabled is being set. The other line still should be converted to use the prop method instead the attr method when setting the disabled property.
Beside that it looks good.
Comment #17
kfritscheI fixed the following things:
1. Re-roll
2. Fixed attr to prop in JQuery as hchonov mentioned
3. Renamed JS have the same name schema as settings
Comment #18
hchonovThank you. After going through the patch again I found one last questionable change:
As in JS we just remove the element which has the class "content-lock-actions" we do not really have to add the class to each action, but only to the parent element containing all the actions. Do you agree with that or there is probably some other reason for doing this?
Comment #19
kfritsche@hchonov:
The class to actions was added later to be able to add the unlock button with the ajax response.
The basic idea at the beginning was to be as close as possible to the none-js version. But you are right, currently we would remove the hole actions.
On the other hand the question is more, if it makes more sense to remove all actions also in none JS version, when content is locked. Are there actions which should be available when locked?
Comment #20
hchonovWell even if there are actions which should be available then this would be a contrib/custom case, which we don't know. Also currently we would add the class to only core known actions, but not to all actions that have been added through e.g. a form alter hook. Therefore currently I think we should add the class to the parent element and remove or disable (personally I prefer disable with e.g. on hover message that the action is disabled because the form is locked) all the action buttons through JS.
Comment #21
kfritsche* Fixed a bad merge in ContentLockController
* In JS action buttons are now only disabled with a tooltip that content is locked and action is not available
Comment #22
hchonovThank you, I think that this looks good now.
Comment #23
chr.fritsch#2916747: Consider the form operation when locking landed, this needs a reroll
Comment #24
kfritscheBig thumbs up to @chr.fritsch for getting all the patches so quickly in. I remove my intermediate github repo now.
Here is just the re-roll.
Comment #25
chr.fritschThank you everyone.