Problem/Motivation
A PHP notice can be thrown when convertAttributes() expects the array key below to exist, but it doesn't.
The key might not exist in the edge case where a custom toolbar link is added and it's set to expanded, but it doesn't have any children.
Steps to reproduce
/**
* Implements hook_toolbar_alter().
*/
function hook_toolbar_alter(&$items) {
if (!empty($items['administration']['tray']['toolbar_administration']))) {
$items['administration']['tray']['toolbar_administration']['#pre_render'][] = 'some_function_add_dashboard';
}
}
function some_function_add_dashboard(array $build) {
$build['administration_menu']['#items']['dashboard'] = [
'is_expanded' => TRUE,
'title' => t('Dashboard'),
'url' => Url::fromRoute('some_module.dashboard', [], [
'attributes' => [
'title' => t('Dashboard'),
'class' => ['toolbar-icon'],
],
]
),
'attributes' => new Attribute([
'class' => [
'menu-item',
'menu-item--expanded',
],
])
];
return $build;
}
If the item is not set to expanded, the notice is not thrown.
Proposed resolution
Add a defensive check around the lines checking the array key in convertAttributes().
Remaining tasks
n/a
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Comments
Comment #2
bramtenhove commentedAnd the patch attached.
Comment #3
bandanasharma commentedComment #4
abhibhatt commentedplease add the step for reproduce this issue.
Comment #6
markhalliwell