builded submenu links for productions, created new CT page (static)
This commit is contained in:
@@ -23,7 +23,7 @@ class HomeController extends ControllerBase {
|
||||
// presentation
|
||||
$query = \Drupal::entityQuery('node')
|
||||
->condition('status', 1)
|
||||
->condition('nid', 12238);
|
||||
->condition('nid', 12242);
|
||||
// TODO: présentation nid should be a setting
|
||||
|
||||
$pres_nid = $query->execute();
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
# @Last modified time: 20-12-2017
|
||||
# @License: GPL-V3
|
||||
|
||||
use Drupal\Core\Menu\MenuTreeParameters;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
@@ -21,3 +25,56 @@ function edlp_productions_theme($existing, $type, $theme, $path) {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* hook_entity_extra_field_info()
|
||||
*
|
||||
*/
|
||||
function edlp_productions_entity_extra_field_info(){
|
||||
$extra = [];
|
||||
$extra['node']['page']['display']['production_subtree'] = [
|
||||
'label' => t('Subtree'),
|
||||
'description' => 'display prodction menu subtree from current node',
|
||||
'weight' => 99,
|
||||
'visible' => FALSE,
|
||||
];
|
||||
return $extra;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_view().
|
||||
* @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
|
||||
*/
|
||||
function edlp_productions_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
|
||||
$display_settings = $display->getComponent('production_subtree');
|
||||
if (!empty($display_settings)) {
|
||||
$menu_name = 'productions';
|
||||
// Find the menu item corresponding to the entity (node).
|
||||
$menu_link_service = \Drupal::getContainer()->get('plugin.manager.menu.link');
|
||||
$route_params = array('node' => $entity->id());
|
||||
$menu_links = $menu_link_service->loadLinksByRoute('entity.node.canonical', $route_params, $menu_name);
|
||||
if (!empty($menu_links)) {
|
||||
// We found a menu link so we can continue with generating the tree.
|
||||
// First, setup the parameters: we need one level starting with the menu
|
||||
// link we found, but excluding it from the tree.
|
||||
$root_menu_item = reset($menu_links);
|
||||
$menu_parameters = new \Drupal\Core\Menu\MenuTreeParameters();
|
||||
$menu_parameters->setMaxDepth(1);
|
||||
$menu_parameters->setRoot($root_menu_item->getPluginId());
|
||||
$menu_parameters->excludeRoot();
|
||||
// Get the tree.
|
||||
$menu_tree_service = \Drupal::service('menu.link_tree');
|
||||
$tree = $menu_tree_service->load($menu_name, $menu_parameters);
|
||||
// Apply some manipulators (checking the access, sorting).
|
||||
$manipulators = [
|
||||
['callable' => 'menu.default_tree_manipulators:checkNodeAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:checkAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $menu_tree_service->transform($tree, $manipulators);
|
||||
// And the last step is to actually build the tree.
|
||||
$build['production_subtree'] = $menu_tree_service->build($tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user