I have this fatal error on one of my sites when trying to call the core/lib/Drupal/Core/Menu/MenuParentFormSelector.php::parentSelectElement() method with an empty $menu_parent argument.

Issue fork drupal-2950729

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

drugan created an issue. See original summary.

drugan’s picture

StatusFileSize
new755 bytes

This fixed my issue.

drugan’s picture

Status: Active » Needs review
zerolab’s picture

Status: Needs review » Reviewed & tested by the community

This works wonders. Simple and got rid of the pesky warning.

LGTM!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

The fix looks solid but the question is how does this happen and can we add test coverage?

In order to commit a bug fix we need an automated to test to prove that we've fixed the bug and ensure that we don't break it again in the future. For more information about writing tests in Drupal 8 see the following links:

  1. https://www.drupal.org/docs/8/testing
  2. https://api.drupal.org/api/drupal/core%21core.api.php/group/testing/8.5.x
+++ b/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php
@@ -85,7 +85,7 @@ public function parentSelectElement($menu_parent, $id = '', array $menus = NULL)
+      if ($menu_parent && !isset($options[$menu_parent])) {

I think we can improve this by doing something like if (strpos($menu_parent, ':') !== FALSE && !isset($options[$menu_parent])) { just to be super sure the explode is going to work.

zerolab’s picture

In our case, it happened when the node type should not be added to a menu:

This is the configuration:

langcode: en
status: true
dependencies:
  module:
    - menu_ui
third_party_settings:
  menu_ui:
    available_menus: {  }
    parent: ''
name: Post
type: post
description: 'A generic post'
help: ''
new_revision: true
preview_mode: 0
display_submitted: true

As you can see parent is empty. Which is what triggers the warning.

drugan’s picture

@alexpott

I've encountered the error while working with some client's site to which I don't have access now. I use my own devel module hack for error reporting and see them automatically like this one:

https://www.drupal.org/files/issues/2018-03-24/field-condition-error1.png

So, now I don't even remember how and where the error appeared.

I think we can improve this by doing something like if (strpos($menu_parent, ':') !== FALSE && !isset($options[$menu_parent])) { just to be super sure the explode is going to work.

Again, I am not sure now but what I remember from debugging the case is that somewhere it were output like a bare colon like ":" instead of "PARENT:CHILD". So, your way of testing the variable might not work.

alexpott’s picture

@drugan the colon check will work fine see https://3v4l.org/MRPHq vs https://3v4l.org/Cb3UV

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

ljgra’s picture

I encountered this issue when I installed the module menu_condition, when the menu parent defaults to -None-. The patch fixed it.

pagach’s picture

StatusFileSize
new784 bytes

Encountered this too. Variable check did not work but colon check did. Here's a patch then.

aleevas’s picture

Version: 8.6.x-dev » 8.7.x-dev
aleevas’s picture

Status: Needs work » Needs review
drugan’s picture

StatusFileSize
new778 bytes
ljgra’s picture

Thanks for the patch!

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

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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, +Needs steps to reproduce

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.

Tagging for steps to reproduce. #6 mentions content type that doesn't use a menu, tried replicating on D10 but could not
Was previously tagged for tests that will still need to happen.

Thanks!

_utsavsharma’s picture

StatusFileSize
new771 bytes
new771 bytes

Patch for 10.1.x.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

useernamee’s picture

We're using patch #11 and it fixes our issue.

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

kalpanajaiswal’s picture

kalpanajaiswal’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Hi @kalpanajaiswal FYI turning existing patches to MR isn't credit worthy unless addressing other points which have not been done. So not saving credit.

Steps are still needed.
Issue summary is incomplete

dcam’s picture

Status: Needs work » Postponed (maintainer needs more info)

I tried really hard to reproduce this issue and could not. I can see how it could happen, given some set of circumstances that likely involves a contributed module. I even installed the menu_condition module since there's a related issue in its queue about this same problem. I still couldn't make it happen.

If you are experiencing this issue, then please update the issue summary with detailed steps to reproduce the problem beginning with a fresh installation of Drupal Core.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)
Issue tags: +Bug Smash Initiative

Since steps to reproduce haven't been provided or summary updated going to close out. If still a bug in D11 please re-open