Problem/Motivation

I'm using the Gin theme and I’m running into an issue where the $item['url'] value is null or missing when the getOption() method is called. The error happens in the prototype_prepare_menu_items() function, and after looking into it, I noticed that some of the menu items don't actually have a 'url' key, which seems to be causing the problem.

Error: Call to a member function getOption() on null in prototype_prepare_menu_items() (line 165 of themes/contrib/prototype/prototype.theme).
prototype_prepare_menu_items() (Line: 153)
prototype_preprocess_menu()
call_user_func_array() (Line: 308)
Drupal\Core\Theme\ThemeManager->render() (Line: 497)
Drupal\Core\Render\Renderer->doRender() (Line: 250)
Drupal\Core\Render\Renderer->doRenderRoot() (Line: 141)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 140)
Drupal\Core\Render\Renderer->renderInIsolation() (Line: 167)
Drupal\Core\Render\Renderer->doRenderPlaceholder() (Line: 729)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
Fiber->start() (Line: 737)
Drupal\Core\Render\Renderer->replacePlaceholders() (Line: 262)
Drupal\Core\Render\Renderer->doRenderRoot() (Line: 141)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 140)
Drupal\Core\Render\Renderer->renderInIsolation() (Line: 167)
Drupal\Core\Render\Renderer->doRenderPlaceholder() (Line: 204)
Drupal\Core\Render\Renderer->renderPlaceholder() (Line: 730)
Drupal\big_pipe\Render\BigPipe->renderPlaceholder() (Line: 500)
Drupal\big_pipe\Render\BigPipe->Drupal\big_pipe\Render\{closure}()
Fiber->start() (Line: 507)
Drupal\big_pipe\Render\BigPipe->sendPlaceholders() (Line: 256)
Drupal\big_pipe\Render\BigPipe->sendContent() (Line: 116)
Drupal\big_pipe\Render\BigPipeResponse->sendContent() (Line: 397)
Symfony\Component\HttpFoundation\Response->send() (Line: 20)

I added a check for the absence of the 'url' key in $item using the isset() condition. After doing that, I ended up with an array that looks like this:

array:4 [ ▼
  "title" => "Shortcuts"
  "class" => "shortcuts"
  "icon" => array:1 [ ▼
    "icon_id" => "shortcuts"
  ]
.
.

Proposed resolution

I added an isset() condition to check for the presence of the 'url' key before adding any attributes, like this:

if (isset($item['url'])) {
  
}

I created a patch file for the changes.

CommentFileSizeAuthor
Undefined-array-key-url.patch2.71 KBsujan shrestha

Issue fork prototype-3558706

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

sujan shrestha created an issue. See original summary.

sujan shrestha’s picture

Issue summary: View changes

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

jldust’s picture

Status: Active » Needs review

Additional adjustments to the menu structure to include validation and more structured setup. This needs to be reviewed and tested.

  • jldust committed 79ed5003 on 5.x
    feat: #3558706 Undefined array key "url" in prototype_prepare_menu_items...
jldust’s picture

Status: Needs review » Reviewed & tested by the community

This has been merged in and will be included in the next tagged release.

jldust’s picture

Status: Reviewed & tested by the community » Fixed

This has been included in the most recent release

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.

jldust’s picture

Status: Fixed » Closed (fixed)