production controller retrie production menu links list, fixed js drupalSettings bug
This commit is contained in:
@@ -6,3 +6,19 @@
|
||||
# @Last modified by: bach
|
||||
# @Last modified time: 20-12-2017
|
||||
# @License: GPL-V3
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function edlp_productions_theme($existing, $type, $theme, $path) {
|
||||
// @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
|
||||
return array(
|
||||
'edlp_productions' => array(
|
||||
// 'render element' => '',
|
||||
'file' => 'includes/edlp_productions.inc',
|
||||
'variables' => array(
|
||||
'hello' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
// use Drupal\Core\Url;
|
||||
|
||||
function template_preprocess_edlp_productions(&$vars){
|
||||
// dpm($vars);
|
||||
/*
|
||||
@see https://www.drupal8.ovh/index.php/en/tutoriels/339/render-a-node-or-an-entity
|
||||
*/
|
||||
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
|
||||
// $vars['next_event'] = array(
|
||||
// "#markup"=>"<h3>Prochaine Date</h3>",
|
||||
// "event"=>$view_builder->view($vars['next_event_node'], 'default')
|
||||
// );
|
||||
|
||||
|
||||
}
|
||||
@@ -3,21 +3,67 @@
|
||||
namespace Drupal\edlp_productions\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
// use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
|
||||
class ProductionsController extends ControllerBase {
|
||||
|
||||
// TODO: generate the menu, how ?
|
||||
|
||||
private function query() {
|
||||
// TODO: get the production menu
|
||||
// @see https://api.drupal.org/api/drupal/core%21modules%21menu_ui%21menu_ui.module/8.6.x
|
||||
// @see https://drupal.stackexchange.com/questions/200893/get-menu-link-page-settings-from-view-configuration
|
||||
$menu_name = 'productions';
|
||||
|
||||
$query = \Drupal::entityQuery('menu_link_content')
|
||||
->condition('menu_name', $menu_name)
|
||||
->condition('enabled', 1)
|
||||
->sort('weight', 'ASC');
|
||||
|
||||
$result = $query->execute();
|
||||
// dpm($result);
|
||||
|
||||
foreach ($result as $id) {
|
||||
$menu_link = MenuLinkContent::load($id);
|
||||
// dpm($menu_link->getParentId());
|
||||
if($menu_link->getParentId() === ""){
|
||||
dpm($menu_link->getTitle());
|
||||
$path = $menu_link->getUrlObject()->getInternalPath();
|
||||
preg_match('/^node\/(\d+)$/', $path, $m);
|
||||
dpm($m[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: loop through first level
|
||||
// TODO: load nodes
|
||||
// TODO: create items
|
||||
// TODO: apply right display
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function toRenderable(){
|
||||
$this->query();
|
||||
// dpm($this->future_nodes);
|
||||
|
||||
// TODO: add localtasks to each nodes : https://api.drupal.org/api/drupal/core%21includes%21menu.inc/function/menu_primary_local_tasks/8.2.x
|
||||
|
||||
return array(
|
||||
"#theme"=>'edlp_productions',
|
||||
"#hello"=>'Hello',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display productions as a page.
|
||||
*
|
||||
* @return renderable array
|
||||
*/
|
||||
public function productions() {
|
||||
return array(
|
||||
"#markup"=>"Edlp Productions"
|
||||
);
|
||||
return $this->toRenderable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,9 +74,7 @@ class ProductionsController extends ControllerBase {
|
||||
public function productionsjson() {
|
||||
|
||||
$response = new JsonResponse();
|
||||
$renderable = array(
|
||||
"#markup"=>"Edlp Productions"
|
||||
);
|
||||
$renderable = $this->toRenderable();
|
||||
$rendered = render($renderable);
|
||||
|
||||
$response->setData([
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{{ hello }}
|
||||
Reference in New Issue
Block a user