history nav is now ok

This commit is contained in:
Bachir Soussi Chiadmi
2018-04-03 15:00:13 +02:00
parent f3fc776b71
commit 4e01b68f5b
20 changed files with 810 additions and 554 deletions
@@ -3,6 +3,9 @@
namespace Drupal\edlp_ajax\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Url;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -29,18 +32,6 @@ class EdlpAjaxController extends ControllerBase {
}
}
/**
* Display entity as a page.
*
* @return renderable array
*/
public function entity($entity_type, $id, $viewmode) {
$this->entity_type = $entity_type;
$this->id = $id;
$this->viewmode = $viewmode;
return $this->toRenderable();
}
/**
* Get entity as json through ajax.
*
@@ -50,6 +41,7 @@ class EdlpAjaxController extends ControllerBase {
$this->entity_type = $entity_type;
$this->id = $id;
$this->viewmode = $viewmode;
$renderable = $this->toRenderable();
$rendered = render($renderable);
@@ -64,17 +56,43 @@ class EdlpAjaxController extends ControllerBase {
$bundle = NULL;
}
$response = new JsonResponse();
$response->setData([
$data = [
'test' => 'hello edlp ajax',
'id' => $this->id,
'view_mode' => $this->viewmode,
'bundle' => $bundle,
'entity_type' => $this->entity_type,
'rendered'=> $rendered,
]);
];
// if content type page (productions) get the menu items
if($bundle == "page"){
$menuLinkManager = \Drupal::service('plugin.manager.menu.link');
$links = $menuLinkManager->loadLinksByRoute('entity.node.canonical', array('node' => $this->id), 'productions');
// dpm($links, 'links');
$menu_parents = array();
foreach ($links as $link) {
$parents = $menuLinkManager->getParentIds($link->getPluginId());
// dpm($parents, 'parents');
foreach ($parents as $parent_id) {
$parent = $menuLinkManager->getInstance(array('id'=>$parent_id));
// dpm($parent, 'parent');
$url = $parent->getUrlObject();
$sys_path = $url->getInternalPath();
// dpm($sys_path);
$menu_parents[] = $sys_path;
}
}
$data['menu_parents'] = $menu_parents;
}
$response = new JsonResponse();
$response->setData($data);
return $response;
// return array(
// '#markup'=>'hello'
// );
}
}