Problem/Motivation

In #3095893: Remove duplicate "add block" link from block content type view's "Results not found" message we are adding a new post update hook that updates views configs. This has started triggering deprecation errors from other views post update hooks (at this time views_post_update_table_css_class) because ViewsConfigUpdater is created using the classResolver pattern in both the post_update and ViewsHooks::viewPresave which means $view_config_updater->setDeprecationsEnabled(FALSE); does not persist from the post update to the presave.

This is compounded by the fact that for every views post update hook, the presave is called and then all views updates are run again on every view since the presave runs updateAll. This should be fixed in a separate issue. #3529290: ViewsConfigUpdater updates run many times for each update

Steps to reproduce

See https://git.drupalcode.org/issue/drupal-3095893/-/jobs/5480383

Proposed resolution

Turn ViewsConfigUpdater into a service so the class property persists.

Proof this fixes the issue https://git.drupalcode.org/project/drupal/-/merge_requests/12337

Remaining tasks

Review
Commit

API changes

ViewsConfigUpdater is now a service

Issue fork drupal-3529274

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

acbramley created an issue. See original summary.

acbramley’s picture

Issue summary: View changes

acbramley’s picture

Issue summary: View changes
Status: Active » Needs review
acbramley’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Something we can get a test for?

acbramley’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

To do that we need to add public API for getting the deprecationsEnabled flag, IMO this is covered by the other issue but I can see value in keeping a test around.

I've pushed something up. The test only run will fail but that'll be because the service doesn't exist so you'll have to manually edit the post update + presave hooks to see that.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Bug Smash Initiative, +Needs change record

Ran the test-only job here https://git.drupalcode.org/issue/drupal-3529274/-/jobs/5584584 which outputted

1) Drupal\Tests\views\Functional\ViewsConfigUpdaterTest::testDeprecationsFlagPersists
The update failed with the following message: "Failed: Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "Drupal\views\ViewsConfigUpdater". in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 1041 of /builds/issue/drupal-3529274/vendor/symfony/dependency-injection/ContainerBuilder.php)."
/builds/issue/drupal-3529274/core/tests/Drupal/Tests/UpdatePathTestTrait.php:68
/builds/issue/drupal-3529274/core/modules/views/tests/src/Functional/ViewsConfigUpdaterTest.php:67
FAILURES!
Tests: 1, Assertions: 5, Failu

I searched the repo for "\Drupal::classResolver(ViewsConfigUpdater" and all 4 instances have been replaced.

Can we get a CR about this being a service and how should be used going forward.

acbramley’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Believe all feedback has been addressed

  • longwave committed e19ac2e6 on 11.x
    Issue #3529274 by acbramley, smustgrave: ViewsConfigUpdater $...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Tried to think of downsides or problems with converting this to a service, but apart from a tiny bit of additional bloat in the container I don't think there are any issues.

Committed e19ac2e and pushed to 11.x. Thanks!

As a bug fix this is technically eligible for backport, but given this is only to fix a problem in a not-yet-committed issue I think this can remain in 11.x only.

Status: Fixed » Closed (fixed)

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