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.
| Comment | File | Size | Author |
|---|---|---|---|
| Undefined-array-key-url.patch | 2.71 KB | sujan shrestha |
Issue fork prototype-3558706
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
Comment #2
sujan shrestha commentedComment #5
jldust commentedAdditional adjustments to the menu structure to include validation and more structured setup. This needs to be reviewed and tested.
Comment #7
jldust commentedThis has been merged in and will be included in the next tagged release.
Comment #8
jldust commentedThis has been included in the most recent release
Comment #10
jldust commented