Problem/Motivation

If you create a menu, enable it on a content type, then remove it, the menu is not removed from the content type's config.

Steps to reproduce

  1. Install Drupal
  2. Create a new menu
  3. Edit the basic page content type and add the new menu as available
  4. Delete the menu
  5. View the content type config yml (via config export)
  6. Deleted menu is not removed from yml file

Proposed resolution

Ensure the menu is removed from config when it is deleted.

Remaining tasks

  • Write a patch with tests
  • Review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3337882

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

pameeela created an issue. See original summary.

enaznin’s picture

Followed the steps and tried the same version (10.1.x-dev) to reproduce the issue, but it's working as expected.

rodrigoaguilera’s picture

Maybe here we can also tackle the empty third party setting

pameeela’s picture

Issue summary: View changes

Clarified IS as it’s in the .yml config which I’m guessing was not clear. It is definitely happening.

enaznin’s picture

Thanks, @pameeela, yes that point was not clear.

enaznin’s picture

Status: Active » Needs review

Let me know if the patch needs modification

smustgrave’s picture

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

Didn't see a patch or open MR to review?

enaznin’s picture

Status: Needs work » Needs review
smustgrave’s picture

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

Left a comment on the MR.

Also will require test coverage.

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.

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

dcam changed the visibility of the branch 11.x to hidden.

dcam changed the visibility of the branch 10.1.x to hidden.

dcam changed the visibility of the branch 3337882-deleted-menus-are to hidden.

dcam’s picture

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

The first MR took the wrong approach, which was removing the settings in the menu delete form submission step. But this would have left the settings in the event that a menu was deleted by some other means. That MR needed to be closed anyway since it was for a D10 branch. But the code for doing the setting removal was still fundamentally good even though it was put in the wrong place. So I copied it to a hook_ENTITY_TYPE_delete() implementation and used it as a starting point. Then I added a Kernel test.

dcam’s picture

Status: Needs review » Needs work

I just realized that I messed up and removed the check for the parent setting being set to a specific link. I'll fix it later.

dcam’s picture

Status: Needs work » Needs review
anjuelsaphilip2020’s picture

StatusFileSize
new92.82 KB
new85.78 KB

Hi, I've verified and tested MR! 11946 and applied the patch successfully on 11. x-dev Version: The changes are working as expected.

  1. Create a New Menu Type: Go to /admin/structure/Menus/Add Menus, Give it a name (eg : Test Menu), Save.
  2. Add the Menu to a Content Type: Go to Structure > Content types > Basic page > Manage fields>Edit >Menu settings, Under "Available menus", check your new Test Menu, Save
  3. Delete the Menu: Go back to Structure > Menus, delete the Test Menu.
  4. Check if Config is Still There: Go to Configuration > Development > Configuration Synchronization, Click Export, Click Single item, Choose Content type, Select Basic page, Click Export
  5. Now open the exported YAML and check

Testing Result:
After you delete the menu, it will be removed from this YAML export automatically. Hence, the changes are working as expected.

Attaching the screenshot for reference.

anjuelsaphilip2020’s picture

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

Status: Reviewed & tested by the community » Needs review
snehal-chibde’s picture

StatusFileSize
new153.55 KB
new140.74 KB
new54.91 KB

Hi, I've verified and tested MR! 11946 on 11. 2-dev Drupal version.
Followed the same steps as #22, the changes are not coming as expected.

Testing Result:
After you delete the menu, it is still visible in this YAML export automatically.

Attaching the screenshot for reference.

tirupati_singh’s picture

Assigned: Unassigned » tirupati_singh
Status: Needs review » Needs work
StatusFileSize
new133.34 KB
new138.25 KB
new356.54 KB

Hi all, I've followed the steps to reproduce the issue and confirm that the issue persists.

  1. Created a new Menu i.e., Explore Drupal.
  2. Enabled the newly created menu to a content type under the Menu settings > Available menus
  3. Exported the config using the drush cex command.
  4. Now deleted the newly Menu.
  5. Again, exported the config using the drush cex command.

Upon exporting the config for the first time, the new menu config has been exported and the content type config got modified with the changes in node.type.content_type_machine_name.yml file as follows under settings

third_party_settings:
  menu_ui:
    available_menus:
      - explore-drupal
      - main
      - tools
    parent: 'explore-drupal:'

and a new new config file "config/sync/system.menu.explore-drupal.yml" has been created for new menu.

After deleting the new menu, and exporting the configs with the same drush command did the following changes:

  1. Deleted the config file "config/sync/system.menu.explore-drupal.yml"
  2. However, the content type that were using the Menu, it's config file didn't get modify and the config remains the same.
    third_party_settings:
      menu_ui:
        available_menus:
          - explore-drupal
          - main
          - tools
        parent: 'explore-drupal:'

I applied the provided MR !11946 and it applied cleanly without any errors. I followed the same above steps and tried deleting the menu. However, on deleting the menu getting this errors:

The website encountered an unexpected error. Try again later.

Error: Call to a member function getStorage() on null in Drupal\menu_ui\Hook\MenuUiHooks->menuDelete() (line 262 of core/modules/menu_ui/src/Hook/MenuUiHooks.php).

And also getting the below error message

Warning: Undefined property: Drupal\menu_ui\Hook\MenuUiHooks::$entityTypeManager in Drupal\menu_ui\Hook\MenuUiHooks->menuDelete() (line 276 of core/modules/menu_ui/src/Hook/MenuUiHooks.php).

Tested on Drupal 11.1.7

Since, the provided MR is not resolving the issue and some changes still required to resolve the issue hence, I'm moving it to Needs work. I'm attaching the screenshots of before and after fixes for reference. Additionally, I'm looking into the above encountered issue.

Thanks!

tirupati_singh’s picture

Assigned: tirupati_singh » Unassigned
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new104.73 KB
new187.18 KB

Hi, after debugging the error:
Warning: Undefined property: Drupal\menu_ui\Hook\MenuUiHooks::$entityTypeManager in Drupal\menu_ui\Hook\MenuUiHooks->menuDelete() (line 276 of core/modules/menu_ui/src/Hook/MenuUiHooks.php).
that I encountered while deleting the menu, I found that it was fixed in the issue Deleting a menu link from the node edit form does not apply hook_ENTITY_TYPE_access(). The MR changes for the fixes were merged in the 11.x branch. Since I was testing on Drupal version 11.1.7, and its branch was 11.1.x, hence I was getting the error as the changes were not merged on the 11.1.x branch.

After applying both the MRs MR !11321 and MR !11946 as patch the encountered error is getting resolved. Now, on deleting menu, I'm not getting any error and also there's no error message appearing for the $entityTypeManager. After deleting the menu that has been enabled for a content type is also getting removed from the content type configuration upon exporting the configuration. I'm attaching the screenshots of after fixes for reference.

As the changes are working fine and MR is resolving the issue, and the pipeline was passing all the tests previously before pulling the latest changes from the source branch. Hence, I'm changing the issue status to RTBC.

Thanks!

catch’s picture

Status: Reviewed & tested by the community » Needs work

Couple of questions on the MR.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

I addressed the feedback with no edits. Restoring RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the response - replied on the MR.

dcam’s picture

Status: Needs work » Needs review

I addressed the feedback and made code changes.

catch’s picture

Status: Needs review » Needs work

Thanks the check looks right but we should inject ModuleHandler here now.

dcam’s picture

Thanks the check looks right but we should inject ModuleHandler here now.

I didn't do it initially because IIRC it's on the roadmap to split up these bulk Hook classes and wasn't sure if it mattered. Also, the procedural call is used throughout the other hooks. So I decided to err on the side of following the example of what was done elsewhere in the class.

I took @berdir's suggestion of checking for the node_type definition so there's no new dependency.

dcam’s picture

Status: Needs work » Needs review
roshanibhangale’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new142.61 KB
new143.4 KB
new139.94 KB
new141.95 KB

Hi,

I have tested this ticket on the Drupal 11.x, and working as expected.

Steps followed:

  1. Create a New Menu Type (/admin/structure/Menus/Add Menus), Save.
  2. Add the Menu to a Content Type (Structure > Content types > Basic page > Manage fields>Edit >Menu settings)
  3. Select the newly created menu from "Available menus", Save
  4. Delete the newly created Menu (Structure > Menus)
  5. Check if Config is Still There (Configuration > Development > Configuration Synchronization),
  6. Go to Export > Single item, Choose Content type, Select Basic page, Click Export
  7. Now open the exported YAML and check

After applying the patch successfully, able to see the menu is removed from config when it is deleted.

Hence moving this to RTBC+1

Attaching the screenshot for the reference.

  • catch committed fbe37854 on 11.2.x
    Issue #3337882 by dcam, enaznin, tirupati_singh, pameeela, catch,...

  • catch committed 1127f443 on 11.x
    Issue #3337882 by dcam, enaznin, tirupati_singh, pameeela, catch,...
catch’s picture

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

::hasDefinition() is great, solves the same problem without the new dependency.

Note I'm not crediting various commenters here who manually tested the issue and posted screenshots - there is no visual bug to verify here, it's a config issue that already has automated test coverage and is easy to reproduce, so going through manual reproduction steps on top of that doesn't really help to fix the issue. Issues that need manual verification are usually CSS or markup issues where it's not easy to write automated test coverage and will usually have the 'needs screenshots' tag.

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

Status: Fixed » Closed (fixed)

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