Problem/Motivation
Part of the efforts:
- #3566536: [meta] eliminate core .module files
- #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset()
Proposed resolution
Deprecate in 11.4 for removal in 13.0:
views_ui_add_ajax_trigger()views_ui_standard_display_dropdown()views_ui_build_form_url()views_ui_form_button_was_clicked()views_ui_add_limited_validation()views_ui_add_ajax_wrapper()views_ui_ajax_update_form()views_ui_nojs_submit()
Move functions to 2 new traits:
- \Drupal\views\ViewsFormAjaxHelperTrait
-
views_ui_add_ajax_trigger()and subsequent code:views_ui_add_limited_validation()views_ui_add_ajax_wrapper()views_ui_ajax_update_form()views_ui_nojs_submit()
- \Drupal\views\ViewsFormHelperTrait
-
views_ui_standard_display_dropdown()views_ui_build_form_url()views_ui_form_button_was_clicked()
Alternative proposed solution
In order to solve the injection of services in the 2 new traits, it was proposed to convert them into services. We tried this in one of the commits. After a discussion with @berdir in the MR, I've reverted that approach. Here are the main reasons:
- We expose as public methods that have no value as API (yes, I know we can tag them as internal, but still...)
- Trying to obtain DI purity for the 2 traits, we run in other DI issues:
DisplayPluginBasehas a lot of subclasses -> we need to add or update all their constructors- We need to add constructors to all descendants of
\Drupal\views\Plugin\views\field\EntityFieldplugin - Same for
WizardPluginBaseand it has a lot of descendants - Same for
\Drupal\views_ui\Form\Ajax\ViewsFormBaseand it has 10 inheritors only in core. This class doesn't even have a constructor currently
A service approach would create more problems than it would solve. The impact on core and contrib can be significant. Traits seem to me a good solution even we compromise on using \Drupal::service() in 2-3 places but it helps us to keep a smaller footprint everywhere around.
Finally, traits are reusable code, which for me is more like procedural code and I see \Drupal::service() in traits acceptable because a trait doesn't know where will be used.
Eventually we went with the solution proposed by @berdir, to add service getters in traits.
Remaining tasks
None.
User interface changes
None.
API changes
The whole core/modules/views_ui/admin.inc file is deprecated and the procedural functions are moved to \Drupal\views\ViewsFormHelperTrait and \Drupal\views\ViewsFormAjaxHelperTrait traits
Data model changes
None.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3035340
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3035340-deprecate-viewsuiaddajaxtrigger
changes, plain diff MR !14615
Comments
Comment #3
claudiu.cristeaPatch.
Comment #4
claudiu.cristeaUnused statements.
Comment #5
claudiu.cristeaComment #7
claudiu.cristeaThe internal should be static.
Comment #8
claudiu.cristeaMoved the deprecation test to a Kernel test as it's more appropriate.
Comment #9
kim.pepperAlthough it's not finalized, it would be good to use the format in #3024461: Adopt consistent deprecation format for core and contrib deprecation messages
Not really sure about the changes in here?
Ditto above
Comment #10
lendudeI see this is not adding new Functional javascript tests, so this depends on the current coverage being sufficient to make this move safely.
Before doing this I would recommend doing an analysis of existing test coverage for the functionality that is being moved. I know there is SOME coverage for this, but a more in depth review of that is in order I think.
Comment #11
claudiu.cristea@kim.pepper, thank you
Well, we cannot use the trait in the deprecated function, so we keep the old code. This we did also in other places. In the same time the scope of this issue is to remove
drupal_static()& Co. So, I replaceddrupal_static()with a static variable for$seen_buttons, as$seen_idswas not used at all. Anyway this will be removed with the deprecated code in 9.0.x.@Lendude,
Not sure what you mean. Lack of coverage should be addressed in other issue. Could you, please, elaborate?
Comment #12
yogeshmpawarRe-roll of #11, because it has failed to apply on 8.8.x branch.
Comment #14
andypostComment #15
claudiu.cristeaReroll
Comment #19
shaktikComment #20
shaktikComment #22
andypostchanging base class is weird, better to set new property in create()
Looks callable should be replaced for 9.x
Comment #23
andypostFix #22.1 and needs work for callable - it looks not best idea to put callable (
views_ui_ajax_update_form()) into traitComment #28
andypostre-roll for 9.5
Comment #29
andypostadded deprecation mamba
Comment #31
andypostComment #32
lendudeUnassigning myself, the fact that we have failing tests here seems like a good indication that we have test coverage for this method.
Comment #35
claudiu.cristeaComment #36
claudiu.cristeaHiding old patches
Comment #38
claudiu.cristeaI've deprecated the whole core/modules/views_ui/admin.inc
Comment #39
claudiu.cristeaReady for review
Comment #40
claudiu.cristeaComment #41
claudiu.cristeaComment #42
claudiu.cristeaComment #43
claudiu.cristeaDecided to split the trait in 2 traits because not all code is needed everywhere. The views_ui_add_ajax_trigger() function plus related callbacks are moved to one trait. The rest, to the other.
Comment #44
claudiu.cristeaReady for a new review
Comment #45
nicxvan commentedI think this is ready.
This was actually very tricky to review.
There are a couple of methods that need to remain static because forms in plugins can't call them otherwise. https://git.drupalcode.org/project/drupal/-/merge_requests/14615#note_67...
There is a really clever BC class in the file for the traits.
I confirmed all deprecation versions are 11.4 and removals line up with the policy 12 for callbacks and _ and 13 for api functions.
Deprecation messages describe the function and replacements correctly.
I pulled it down and there are no more loadIncludes for this file either.
Only question is the config call if we should add that as a dependency. I think it can be a follow up since this is already tricky.
Comment #46
berdir> There are a couple of methods that need to remain static because forms in plugins can't call them otherwise.
That's correct, plugins can't define their own non-static callbacks because it's not possible to access their instance from somewhere, it's neither a service nor the known form object.
> There is a really clever BC class in the file for the traits.
I was wondering if it's just clever or maybe a bit too clever (as in something we should have test coverage for). I think it's fine, I'd also be fine with keeping the code, but per my added review, we likely need to move the functions to the .module file, so it's nice to not having to duplicate the code.
Comment #47
nicxvan commentedThere was a fairly long discussion in slack around various strategies for dependency injection with traits. https://drupal.slack.com/archives/C079NQPQUEN/p1770230131118289
The short answer is that it is very complex and we don't have a standard yet.
I think the key takeaway is that these two items should be normal services even if they are a bit light and we can just handle things normally.
It's not ideal, but probably the cleanest we can do here.
Comment #48
claudiu.cristeaComment #49
claudiu.cristeaReverted to traits for the reasons explained in MR and in the updated IS. I think it's the most practical, compact and less disruptive solution. Ready again for review
Comment #50
nicxvan commentedI'm on board with that pivot back, I think it's cleaner than the services, thank you for exploring that.
There is one thing to resolve still on the MR which is the magic autoloading that berdir caught.
Comment #51
claudiu.cristeaOk, reverted the removal of .inc file inclusion. Also reverted some unnecessary DI as we rely now on protected service getters
Comment #52
nicxvan commentedThis is good now, glad we got the extra cleanup in too.
Comment #53
godotislateDiscussed the removal version of the form/AJAX callbacks functions with @xjm, and these were our general thoughts:
For removing in D12:
These aren't specifically API functions
No found usages in contrib search
For removing in D13
There aren't underscore functions, and they're not documented as internal
Consistency of removal across all deprecated functions in this issue
Timeline to D12 release getting closer and todo list is long
Our conclusion was to make D13 the removal version, so updating the IS.
I think a reasonable general guideline about removal versions is if there's a question, go with 13.
Comment #54
nicxvan commentedYes those are the guidelines we've been following for this initiative, it had been agreed that callbacks should be able to be removed in 12, but I don't think it's a huge burden to bump to 13.
I just reviewed your commit and it looks right for bumping the version.
Comment #57
godotislateCommitted and pushed a2bcba1 to main. and 52711e6 to 11.x. Thanks!