It is possible that someone could delete a view or other route that we are assuming is there. We need to fence off the routes in case they are not available.
Create a function:
function routeExists($name)
{
// I assume that you have a link to the container in your twig extension class
$router = \Drupal::service('router');
return (null === $router->getRouteCollection()->get($name)) ? false : true;
}
...
'manage_content' => [
'#title' => t('Manager Role and Content'),
'#description' => t('Ensure managers have the ability to manage content.'),
'handbook_page' => [
'#text' => t('Site User Roles'),
'#url' => routeExists('user.admin_permissions') ? Url::fromRoute('user.admin_permissions') : '',
],
],
or you could do something like this and use the routeExists function
/**
* Generates and returns section 6 for launch_checklist.
*/
function section_06_content($checklist_routes) {
$sections = [];
...
if (routeExists('user.admin_permissions')) {
$sections['manage_content'] = [
'#title' => t('Manager Role and Content'),
'#description' => t('Ensure managers have the ability to manage content.'),
'handbook_page' => [
'#text' => t('Site User Roles'),
'#url' => Url::fromRoute('user.admin_permissions'),
],
];
}
...
// Add the rest of the routes checking to see if they exist.
return $sections;
}
OR, a try/catch without the need for the function.
/**
* Generates and returns section 6 for launch_checklist.
*/
function section_06_content($checklist_routes) {
$sections = [];
...
try {
$sections['manage_content'] = [
'#title' => t('Manager Role and Content'),
'#description' => t('Ensure managers have the ability to manage content.'),
'handbook_page' => [
'#text' => t('Site User Roles'),
'#url' => Url::fromRoute('user.admin_permissions'),
],
];
} catch (\Exception $e) {}
...
// Add the rest of the routes checking to see if they exist.
return $sections;
}