| 
														
															@@ -32,9 +32,15 @@ function edlp_productions_theme($existing, $type, $theme, $path) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 */ 
														 | 
														
														 | 
														
															 */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 function edlp_productions_entity_extra_field_info(){ 
														 | 
														
														 | 
														
															 function edlp_productions_entity_extra_field_info(){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   $extra = []; 
														 | 
														
														 | 
														
															   $extra = []; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  $extra['node']['page']['display']['production_parent'] = [ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    'label' => t('Production Parent'), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    'description' => 'display production menu parent from current node', 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    'weight' => 99, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    'visible' => FALSE, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  ]; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   $extra['node']['page']['display']['production_subtree'] = [ 
														 | 
														
														 | 
														
															   $extra['node']['page']['display']['production_subtree'] = [ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    'label' => t('Subtree'), 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    'description' => 'display prodction menu subtree from current node', 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    'label' => t('Production Subtree'), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    'description' => 'display production menu subtree from current node', 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     'weight' => 99, 
														 | 
														
														 | 
														
															     'weight' => 99, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     'visible' => FALSE, 
														 | 
														
														 | 
														
															     'visible' => FALSE, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   ]; 
														 | 
														
														 | 
														
															   ]; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -47,34 +53,63 @@ function edlp_productions_entity_extra_field_info(){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8 
														 | 
														
														 | 
														
															  * @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) { 
														 | 
														
														 | 
														
															 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)) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  $parent_display_settings = $display->getComponent('production_parent'); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  $subtree_display_settings = $display->getComponent('production_subtree'); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+  if (!empty($parent_display_settings) || !empty($subtree_display_settings)) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     $menu_name = 'productions'; 
														 | 
														
														 | 
														
															     $menu_name = 'productions'; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     // Find the menu item corresponding to the entity (node). 
														 | 
														
														 | 
														
															     // Find the menu item corresponding to the entity (node). 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     $menu_link_service = \Drupal::getContainer()->get('plugin.manager.menu.link'); 
														 | 
														
														 | 
														
															     $menu_link_service = \Drupal::getContainer()->get('plugin.manager.menu.link'); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     $route_params = array('node' => $entity->id()); 
														 | 
														
														 | 
														
															     $route_params = array('node' => $entity->id()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     $menu_links = $menu_link_service->loadLinksByRoute('entity.node.canonical', $route_params, $menu_name); 
														 | 
														
														 | 
														
															     $menu_links = $menu_link_service->loadLinksByRoute('entity.node.canonical', $route_params, $menu_name); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     if (!empty($menu_links)) { 
														 | 
														
														 | 
														
															     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. 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      // We found a menu link 
														 | 
													
												
											
												
													
														| 
														 | 
														
															       $root_menu_item = reset($menu_links); 
														 | 
														
														 | 
														
															       $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'); 
														 | 
														
														 | 
														
															       $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); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      // parent 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if(!empty($parent_display_settings)){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        $parents_ids = $menu_link_service->getParentIds($root_menu_item->getPluginId()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        if(count($parents_ids) > 1){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          // dpm($parents_ids); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          $root_parent_menu_item_id = array_pop($parents_ids); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          $menu_parameters = new \Drupal\Core\Menu\MenuTreeParameters(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          $menu_parameters->setMaxDepth(0); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          $menu_parameters->setRoot($root_parent_menu_item_id); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+          // Get the 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_parent'] = $menu_tree_service->build($tree); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      // subtree 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      if(!empty($subtree_display_settings)){ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // 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. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        $menu_parameters = new \Drupal\Core\Menu\MenuTreeParameters(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        $menu_parameters->setMaxDepth(1); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        $menu_parameters->setRoot($root_menu_item->getPluginId()); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        $menu_parameters->excludeRoot(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        // Get the 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); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+      } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     } 
														 | 
														
														 | 
														
															     } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															   } 
														 | 
														
														 | 
														
															   } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 } 
														 | 
														
														 | 
														
															 } 
														 |