Problem/Motivation

Part of the efforts:

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:
    • DisplayPluginBase has 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\EntityField plugin
    • Same for WizardPluginBase and it has a lot of descendants
    • Same for \Drupal\views_ui\Form\Ajax\ViewsFormBase and 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.

Issue fork drupal-3035340

Command icon 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:

Comments

claudiu.cristea created an issue. See original summary.

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

Status: Active » Needs review
StatusFileSize
new21.35 KB

Patch.

claudiu.cristea’s picture

Issue summary: View changes
StatusFileSize
new21.3 KB
new650 bytes

Unused statements.

claudiu.cristea’s picture

Component: views.module » views_ui.module

Status: Needs review » Needs work

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

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new1.47 KB
new21.31 KB

The internal should be static.

claudiu.cristea’s picture

StatusFileSize
new7.74 KB
new21.21 KB

Moved the deprecation test to a Kernel test as it's more appropriate.

kim.pepper’s picture

  1. +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
    @@ -146,6 +168,12 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    +      @trigger_error('The $element_info parameter will become mandatory before Drupal 9.0.0. See https://www.drupal.org/node/3040111.', E_USER_DEPRECATED);
    

    Although it's not finalized, it would be good to use the format in #3024461: Adopt consistent deprecation format for core and contrib deprecation messages

  2. +++ b/core/modules/views_ui/admin.inc
    @@ -39,10 +39,19 @@
    +  static $seen_buttons = [];
    

    Not really sure about the changes in here?

  3. +++ b/core/modules/views_ui/src/ViewAddForm.php
    @@ -22,14 +25,28 @@ class ViewAddForm extends ViewFormBase {
    +      @trigger_error('The $element_info parameter will become mandatory before Drupal 9.0.0. See https://www.drupal.org/node/3040111.', E_USER_DEPRECATED);
    

    Ditto above

lendude’s picture

I 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.

claudiu.cristea’s picture

Assigned: Unassigned » lendude
Issue tags: +DevDaysTransylvania
StatusFileSize
new3.55 KB
new22.92 KB

@kim.pepper, thank you

Not really sure about the changes in here?

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 replaced drupal_static() with a static variable for $seen_buttons, as $seen_ids was not used at all. Anyway this will be removed with the deprecated code in 9.0.x.

@Lendude,

(...) 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.

Not sure what you mean. Lack of coverage should be addressed in other issue. Could you, please, elaborate?

yogeshmpawar’s picture

StatusFileSize
new21.52 KB

Re-roll of #11, because it has failed to apply on 8.8.x branch.

Status: Needs review » Needs work

The last submitted patch, 12: 3035340-12.patch, failed testing. View results

andypost’s picture

claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -DevDaysTransylvania
StatusFileSize
new21.62 KB

Reroll

Status: Needs review » Needs work

The last submitted patch, 15: 3035340-15.patch, failed testing. View results

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.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

shaktik’s picture

StatusFileSize
new18.08 KB
shaktik’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: 3035340-19.patch, failed testing. View results

andypost’s picture

  1. +++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
    @@ -124,14 +135,25 @@ public static function create(ContainerInterface $container, array $configuratio
    +  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, ElementInfoManagerInterface $element_info = NULL) {
    
    @@ -144,6 +166,12 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    +    if (!$element_info) {
    +      @trigger_error('The $element_info parameter will become mandatory before Drupal 9.0.0. See https://www.drupal.org/node/3040111.', E_USER_DEPRECATED);
    
    +++ b/core/modules/views_ui/src/ViewAddForm.php
    @@ -22,14 +25,28 @@ class ViewAddForm extends ViewFormBase {
    +    if (!$element_info) {
    +      @trigger_error('Calling WizardPluginBase::__construct() without the $element_info argument is deprecated in drupal:8.8.0 and the $element_info argument will be required in drupal:9.0.0. See https://www.drupal.org/node/3040111', E_USER_DEPRECATED);
    +      $element_info = \Drupal::service('plugin.manager.element_info');
    

    changing base class is weird, better to set new property in create()

  2. +++ b/core/modules/views_ui/admin.inc
    @@ -39,15 +39,22 @@
    + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There's
    ...
    +  @trigger_error("views_ui_add_ajax_trigger() is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. There's no public replacement for this function. Form classes can use the protected method \\Drupal\\views_ui\\ViewsUiFormHelperTrait::addAjaxTrigger(). See https://www.drupal.org/node/3040111.", E_USER_DEPRECATED);
    
    +++ b/core/modules/views_ui/src/ViewsUiFormHelperTrait.php
    @@ -0,0 +1,128 @@
    +    $triggering_element['#ajax']['callback'] = 'views_ui_ajax_update_form';
    

    Looks callable should be replaced for 9.x

andypost’s picture

StatusFileSize
new7.08 KB
new16.09 KB

Fix #22.1 and needs work for callable - it looks not best idea to put callable (views_ui_ajax_update_form()) into trait

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.

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.

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.

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.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.53 KB
new16.33 KB

re-roll for 9.5

andypost’s picture

StatusFileSize
new7.62 KB
new21.26 KB

added deprecation mamba

Status: Needs review » Needs work

The last submitted patch, 29: 3035340-29.patch, failed testing. View results

andypost’s picture

Version: 9.5.x-dev » 10.1.x-dev
lendude’s picture

Assigned: lendude » Unassigned

Unassigning myself, the fact that we have failing tests here seems like a good indication that we have test coverage for this method.

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

claudiu.cristea’s picture

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Hiding old patches

claudiu.cristea’s picture

Title: Deprecate views_ui_add_ajax_trigger() » Deprecate core/modules/views_ui/admin.inc
Issue summary: View changes

I've deprecated the whole core/modules/views_ui/admin.inc

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Status: Needs work » Needs review

Ready for review

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes

Decided 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.

claudiu.cristea’s picture

Ready for a new review

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

> 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.

nicxvan’s picture

There 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.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Status: Needs work » Needs review

Reverted 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

nicxvan’s picture

Status: Needs review » Needs work

I'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.

claudiu.cristea’s picture

Status: Needs work » Needs review

Ok, reverted the removal of .inc file inclusion. Also reverted some unnecessary DI as we rely now on protected service getters

nicxvan’s picture

Status: Needs review » Reviewed & tested by the community

This is good now, glad we got the extra cleanup in too.

godotislate’s picture

Issue summary: View changes

Discussed 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.

nicxvan’s picture

Yes 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.

  • godotislate committed 52711e6a on 11.x
    refactor: #3035340 Deprecate core/modules/views_ui/admin.inc
    
    By:...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed a2bcba1 to main. and 52711e6 to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • godotislate committed a2bcba1d on main
    refactor: #3035340 Deprecate core/modules/views_ui/admin.inc
    
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.