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 by: bach
|
||||||
# @Last modified time: 20-12-2017
|
# @Last modified time: 20-12-2017
|
||||||
# @License: GPL-V3
|
# @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;
|
namespace Drupal\edlp_productions\Controller;
|
||||||
|
|
||||||
use Drupal\Core\Controller\ControllerBase;
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
// use Drupal\Core\Datetime\DrupalDateTime;
|
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
|
||||||
class ProductionsController extends ControllerBase {
|
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.
|
* Display productions as a page.
|
||||||
*
|
*
|
||||||
* @return renderable array
|
* @return renderable array
|
||||||
*/
|
*/
|
||||||
public function productions() {
|
public function productions() {
|
||||||
return array(
|
return $this->toRenderable();
|
||||||
"#markup"=>"Edlp Productions"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,9 +74,7 @@ class ProductionsController extends ControllerBase {
|
|||||||
public function productionsjson() {
|
public function productionsjson() {
|
||||||
|
|
||||||
$response = new JsonResponse();
|
$response = new JsonResponse();
|
||||||
$renderable = array(
|
$renderable = $this->toRenderable();
|
||||||
"#markup"=>"Edlp Productions"
|
|
||||||
);
|
|
||||||
$rendered = render($renderable);
|
$rendered = render($renderable);
|
||||||
|
|
||||||
$response->setData([
|
$response->setData([
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{{ hello }}
|
||||||
@@ -88,8 +88,7 @@ edlp_vars = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: drupal settings not defined on NOT front page
|
var path = window.location.origin + drupalSettings.path.baseUrl + sys_path +'/ajax';
|
||||||
var path = window.location.origin + drupalSettings.basepath + sys_path +'/ajax';
|
|
||||||
closeAllModals();
|
closeAllModals();
|
||||||
_$body.addClass('ajax-loading');
|
_$body.addClass('ajax-loading');
|
||||||
$link.addClass('ajax-loading');
|
$link.addClass('ajax-loading');
|
||||||
@@ -104,7 +103,13 @@ edlp_vars = {
|
|||||||
console.log('ajax link loaded : data', data);
|
console.log('ajax link loaded : data', data);
|
||||||
_$content_container.html(data.rendered);
|
_$content_container.html(data.rendered);
|
||||||
_$body.removeClass('ajax-loading');
|
_$body.removeClass('ajax-loading');
|
||||||
_$body.removeClass().addClass('path-'+sys_path);
|
// add body class for currently loaded content
|
||||||
|
_$body.removeClass().addClass('path-'+sys_path.replace(/\//g, '-'));
|
||||||
|
// id node add a generic path-node class to body
|
||||||
|
m = sys_path.match(/^\/?(edlp\/node\/\d+)$/g);
|
||||||
|
if(m){
|
||||||
|
_$body.addClass('path-edlp-node');
|
||||||
|
}
|
||||||
_$ajaxLinks.removeClass('is-active');
|
_$ajaxLinks.removeClass('is-active');
|
||||||
$link.removeClass('ajax-loading').addClass('is-active');
|
$link.removeClass('ajax-loading').addClass('is-active');
|
||||||
initScrollbars();
|
initScrollbars();
|
||||||
|
|||||||
@@ -65,8 +65,7 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: drupal settings not defined on NOT front page
|
var path = window.location.origin + drupalSettings.path.baseUrl + sys_path +'/ajax';
|
||||||
var path = window.location.origin + drupalSettings.basepath + sys_path +'/ajax';
|
|
||||||
closeAllModals();
|
closeAllModals();
|
||||||
_$body.addClass('ajax-loading');
|
_$body.addClass('ajax-loading');
|
||||||
$link.addClass('ajax-loading');
|
$link.addClass('ajax-loading');
|
||||||
@@ -81,7 +80,13 @@
|
|||||||
console.log('ajax link loaded : data', data);
|
console.log('ajax link loaded : data', data);
|
||||||
_$content_container.html(data.rendered);
|
_$content_container.html(data.rendered);
|
||||||
_$body.removeClass('ajax-loading');
|
_$body.removeClass('ajax-loading');
|
||||||
_$body.removeClass().addClass('path-'+sys_path);
|
// add body class for currently loaded content
|
||||||
|
_$body.removeClass().addClass('path-'+sys_path.replace(/\//g, '-'));
|
||||||
|
// id node add a generic path-node class to body
|
||||||
|
m = sys_path.match(/^\/?(edlp\/node\/\d+)$/g);
|
||||||
|
if(m){
|
||||||
|
_$body.addClass('path-edlp-node');
|
||||||
|
}
|
||||||
_$ajaxLinks.removeClass('is-active');
|
_$ajaxLinks.removeClass('is-active');
|
||||||
$link.removeClass('ajax-loading').addClass('is-active');
|
$link.removeClass('ajax-loading').addClass('is-active');
|
||||||
initScrollbars();
|
initScrollbars();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ global-js:
|
|||||||
assets/dist/bower/jquery.overlayScrollbars.min.js: { scope: footer }
|
assets/dist/bower/jquery.overlayScrollbars.min.js: { scope: footer }
|
||||||
assets/dist/scripts/main.min.js: { scope: footer }
|
assets/dist/scripts/main.min.js: { scope: footer }
|
||||||
dependencies:
|
dependencies:
|
||||||
|
- core/drupal
|
||||||
- core/matchmedia
|
- core/matchmedia
|
||||||
- core/matchmedia.addListener
|
- core/matchmedia.addListener
|
||||||
- core/jquery
|
- core/jquery
|
||||||
|
|||||||
Reference in New Issue
Block a user