Problem/Motivation

The system.prepare_modules_entity_uninstall route defines the following _title_callback value:

\Drupal\system\Form\PrepareModulesEntityUninstallForm::formTitle

This was introduced when the route itself was first introduced in #2688945: Allow removing a module's content entities prior to module uninstallation.

However, it never actually existed.

Thus, an error is thrown when attempting to retrieve the title via the title_resolver service manually. I can only suspect that this error is caught in the system when actually visiting the page since no one has actually caught this.

Proposed resolution

Add the _title_callback for this route and test coverage it can be called with the title resolver service

Remaining tasks

  • Review and commit

User interface changes

None

API changes

None

Data model changes

None

Issue fork drupal-2862702

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

markcarver created an issue. See original summary.

markhalliwell’s picture

Issue summary: View changes
markhalliwell’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new995 bytes
markhalliwell’s picture

markhalliwell’s picture

Issue summary: View changes
arifkhn46’s picture

I am facing the same issue, before seeing this ticket I created following ticket:

https://www.drupal.org/node/2876872

arifkhn46’s picture

I applied the patch its working fine.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me as well :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/system.routing.yml
@@ -427,7 +427,7 @@ system.prepare_modules_entity_uninstall:
-    _title_callback: '\Drupal\system\Form\PrepareModulesEntityUninstallForm::formTitle'
+    _title: 'Confirm content uninstall'

Feels like we're missing test coverage somewhere then. Why isn't \Drupal\system\Tests\Module\PrepareUninstallTest::testUninstall() broken? It is because of the theme we're testing in? And how do the title's appear correct?

I guess it because of

$form['#title'] = $this->getQuestion();

in \Drupal\Core\Form\ConfirmFormBase::buildForm()

heddn’s picture

I got this from breadcrumbs. Do we not print breadcrumbs on this page by default?

alexpott’s picture

@heddn breadcrumbs are on in the Seven theme.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

hamrant’s picture

Patch #3 fixed my issue, thanks @markcarver

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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.

peter feddo’s picture

Patch #3 resolved my issue The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">InvalidArgumentException</em>: The controller for URI &quot;&quot; is not callable.

This error would occur when attempting to uninstall a module's entities. After applying the patch and perform a cache rebuild the error is resolved on Drupal 8.7.3 PHP 7.3.5.

alexpott’s picture

Issue tags: -Needs backport to 8.3.x, -needs backport to 8.2.x +Needs tests
+++ b/core/modules/system/system.routing.yml
@@ -427,7 +427,7 @@ system.prepare_modules_entity_uninstall:
+    _title: 'Confirm content uninstall'

I think we should make this exist so that the form title matches the actual form title. So something like:

  /**
   * Gets the form title.
   *
   * @param string $entity_type_id
   *   The entity type ID.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   The form title.
   */
  public function formTitle($entity_type_id = NULL) {
    $this->entityTypeId = $entity_type_id;
    if (!$this->entityTypeManager->hasDefinition($this->entityTypeId)) {
      throw new NotFoundHttpException();
    }
    return $this->getQuestion();
  }

And we're missing test coverage :(

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.

liquidcms’s picture

this not been fixed yet? I have 8.7.7 and still seeing this.

tobiberlin’s picture

+1 for fixing this ;-)

mxr576’s picture

this is 3 years old issue about restoring a form title :)

I do agree with #9 and #18 and I experienced on my own skin that confirm forms make things unpredictable, but the underlying core issue should be resolved in a followup task I believe. (Maybe there won't be a BC solution for confirm forms vs. page titles.)

mxr576’s picture

 public function formTitle($entity_type_id = NULL) {
    $this->entityTypeId = $entity_type_id;
    if (!$this->entityTypeManager->hasDefinition($this->entityTypeId)) {
      throw new NotFoundHttpException();
    }

How this could practically happen if there is a proper access checking on the route?

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.

stefan.korn’s picture

In my case I could drag an issue with this down to Easy Breadcrumb module, see #3164758: Easy breadcrumb breaks the form for removing module content entities data before uninstallation.

But it still does not make sense to me that core defines a _title_callback that is not existing.

It seems that core is not validating (or even using) this _title_callback in its implementation of the PrepareModulesUninstallForm, therefore no error is raised. Easy Breadcrumb is using TitleResolver service and that breaks the form by raising an exception.

What would be the downside or risk of fixing this in core either by implementing the _title_callback in PrepareModulesEntityUninstallForm or using static title like proposed by @markcarver?

ankit agrawal’s picture

Thank you stefan, I also faced the same issue with the easy breadcrumn module and the patch of easy breadcrumb module worked for me. I would definitely be good to have core defines a _title callback that is not existing.

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.

nwom’s picture

Thank you @Ankit Agrawal. My problem was related to Easy Breadcrumbs as well. Updating to the latest dev version fixed it for me.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.72 KB
new3.31 KB

- Added the method formTitle as mentioned in ##1
- Added test case to ensure that title exists and as per the method's output
- Test to ensure that entity deletion process works as expected.

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.

joseph.olstad’s picture

Patch #29 works as expected on Drupal 8.9.14 so assuming it also applies cleanly to 9.0.x , 9.1.x as well as 8.9.x

Thanks so much for your work on this!

Great work everyone above!

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Could we get a test-only patch to show it failing?

If I'm reading the issue correctly, when the page is actually visited, this title callback doesn't get called, because ConfirmForm takes over. Therefore the title callback is only getting called in edge cases like breadcrumbs - but if so I don't think the test coverage is actually exercising this.

Also needs an issue summary update.

+++ b/core/modules/system/src/Form/PrepareModulesEntityUninstallForm.php
@@ -90,6 +90,23 @@ public function getCancelUrl() {
+    }

Additionally, if this is really necessary, it needs a comment as to how we're running this code when the route ought to be a 404.

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.

hswong3i made their first commit to this issue’s fork.

hswong3i’s picture

Status: Needs work » Needs review

PR created from #29

perfectcu.be’s picture

Version: 9.4.x-dev » 8.9.x-dev
StatusFileSize
new2.79 KB
new821 bytes

Thanks for the heads up @joseph.olstad and @mohit_aghera for the original patch! Moving to D9 is easier when you can uninstall modules that are getting in the way of a clean upgrade.

#29 worked for me on 8.9.20 with some fuzz:

cd {my_drupal_root}
patch -p1 < 2862702-28_0.patch 
patching file core/modules/system/src/Form/PrepareModulesEntityUninstallForm.php
Hunk #1 succeeded at 89 (offset -1 lines).
patching file core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
Hunk #1 succeeded at 4 with fuzz 2 (offset 1 line).
Hunk #2 succeeded at 229 with fuzz 1 (offset 6 lines).

Attached is a rerolled version (2862702-38.patch) of #29 that applies cleanly (no fuzz) on 8.9.20 and reroll_diff: reroll_diff-29-38.txt.

NOTE: the reroll name is based on the comment where it was originally posted (#29), not the file suffix on the original patch (-28_0)

mxr576’s picture

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

Drupal 8 is EOL-ed, if this patch needs a reroll then the reroll should be for Drupal 9.4.x otherwise it never gets fixed in core :S

mxr576’s picture

Hiding D8 patches, the MR above which needs review.

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.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Left a few comments in the MR.
Also needs issue summary update per #33

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.

larowlan made their first commit to this issue’s fork.

larowlan credited dscl.

larowlan’s picture

Status: Needs work » Needs review
Issue tags: +DrupalSouth 2024

@dscl and I worked on this at DrupalSouth
it is ready for review now

mstrelan’s picture

Status: Needs review » Needs work

Left some comments on the MR

alexpott’s picture

FWIW the test passes without the fix. That's because we're not actually calling any code results in the title callback being used.

Maybe we should go back to #3. Does this page actually need a title callback - hmmm maybe we do as I guess Easy Breadcrumb is using it.

Anyway to test this we need to use the title resolver service on this route. Visiting the page won't trigger the code because of the #title in the form.

larowlan’s picture

Status: Needs work » Needs review

Addressed feedback

smustgrave’s picture

Status: Needs review » Needs work

Only moving to NW for the issue summary update

Remove the _title_callback for this route and just replace it with a static title. The confirm form overrides this value anyway.

Is that still true?

larowlan’s picture

Issue summary: View changes
larowlan’s picture

Status: Needs work » Needs review
Issue tags: -Needs issue summary update +Bug Smash Initiative
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Summary now appears to match the MR.

  • catch committed d1acf5ca on 10.3.x
    Issue #2862702 by larowlan, hswong3i, mohit_aghera, perfectcu.be,...

  • catch committed f1601a48 on 11.x
    Issue #2862702 by larowlan, hswong3i, mohit_aghera, perfectcu.be,...
catch’s picture

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

Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

Status: Fixed » Closed (fixed)

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