php
UserDashboardController.php
$menu_name = 'my_custom_menu_machine_name';
$menu_tree = \Drupal::menuTree();
// Build the typical default set of menu tree parameters.
$parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
// Load the tree based on this set of parameters.
$tree = $menu_tree->load($menu_name, $parameters);
// Transform the tree using the manipulators you want.
$manipulators = [
// Only show links that are accessible for the current user.
['callable' => 'menu.default_tree_manipulators:checkAccess'],
// Use the default sorting of menu links.
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$menu = $menu_tree->build($tree);
// Set theme for custom styling.
$menu['#theme'] = 'my_custom_theme';
12.03.2026 | Peter Gerken
How to build a menu render array programmatically
./compat.sh gpd setup ./compat.sh gpd run
A small shell-script to check Drupal 7 projects for PHP version compatibility which outputs to csv.
Usage: ./compat.sh projectname (setup|run)
Change Version (in this example: 7.4) when needed.
compat.sh
#!/bin/sh
PROJ=$1
# Setup project dependencies.
if [ "$2" = "setup" ]; then
composer require squizlabs/php_codesniffer
composer require phpcompatibility/php-compatibility
fi
# Run checks.
if [ "$2" = "run" ]; then
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 web/sites/all/modules/ --report-csv="$PROJ"_php73_modules.csv --extensions=php,inc,module -d memory_limit=512M
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 web/sites/all/libraries/ --report-csv="$PROJ"_php73_lib.csv --extensions=php,inc,module -d memory_limit=512M
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.3 web/sites/all/themes/ --report-csv="$PROJ"_php73_themes.csv --extensions=php,inc,module,theme -d memory_limit=512M
fi
27.04.2022 | Nikolas Kopp