reinstalled all contribs with composer

need to run :
drush ev 'drupal_flush_all_caches();'
drush cr
and restart nginx and php-fpm before loading the website
This commit is contained in:
2019-04-30 19:27:47 +02:00
parent e1f9bb3cd0
commit 9da6cf9927
373 changed files with 3392 additions and 5 deletions
@@ -0,0 +1,18 @@
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 13-12-2017
# @Email: bachir@figureslibres.io
# @Filename: edlp_productions.routing.yml
# @Last modified by: bach
# @Last modified time: 20-12-2017
# @License: GPL-V3
name: Edlp Productions
type: module
description: Manage productions for edlp d8.
core: 8.x
package: Edlp
# dependencies:
# - migrate_drupal
# - migrate_plus
# - migrate_tools
@@ -0,0 +1,127 @@
<?php
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 13-12-2017
# @Email: bachir@figureslibres.io
# @Filename: edlp_productions.module
# @Last modified by: bach
# @Last modified time: 20-12-2017
# @License: GPL-V3
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* 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(
'file' => 'includes/edlp_productions.inc',
'variables' => array(
'nodes_entities' => NULL,
),
),
);
}
/**
* hook_entity_extra_field_info()
*
*/
function edlp_productions_entity_extra_field_info(){
$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'] = [
'label' => t('Production Subtree'),
'description' => 'display production 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) {
$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';
// 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
$root_menu_item = reset($menu_links);
$menu_tree_service = \Drupal::service('menu.link_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'] = array(
'#type'=>"container",
'#attributes'=>array(
'class'=>'productions-parent'
),
'menu'=>$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'] = array(
'#type'=>"container",
'#attributes'=>array(
'class'=>'productions-subtree'
),
'menu'=>$menu_tree_service->build($tree)
);
}
}
}
}
@@ -0,0 +1,23 @@
# @Author: Bachir Soussi Chiadmi <bach>
# @Date: 13-12-2017
# @Email: bachir@figureslibres.io
# @Filename: edlp_corpus.routing.yml
# @Last modified by: bach
# @Last modified time: 20-12-2017
# @License: GPL-V3
edlp_productions.productions:
path: '/productions'
defaults:
_controller: '\Drupal\edlp_productions\Controller\ProductionsController::productions'
_title: 'Productions'
requirements:
_permission: 'access content'
edlp_productions.productionsajax:
path: '/productions/ajax'
defaults:
_controller: '\Drupal\edlp_productions\Controller\ProductionsController::productionsjson'
_title: 'Productions'
requirements:
_permission: 'access content'
@@ -0,0 +1,31 @@
<?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');
foreach($vars['nodes_entities'] as $node){
switch($node->get('field_view_mode')->value){
case "1":
$vm = "image_2_columns";
break;
case "2":
$vm = "image_1_columns";
break;
case "3":
$vm = "text_1_column";
break;
};
$vars['nodes'][] = array(
'vm'=>$vm,
'build'=>$view_builder->view($node, $vm)
);
}
}
@@ -0,0 +1,145 @@
<?php
namespace Drupal\edlp_productions\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\Core\Language\LanguageInterface;
use Drupal\menu_link_content\Entity\MenuLinkContent;
// use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\core\render\RenderContext;
class ProductionsController extends ControllerBase {
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);
$nids = [];
foreach ($result as $id) {
$menu_link = MenuLinkContent::load($id);
// dpm($menu_link->getParentId());
if($menu_link->getParentId() !== "") continue;
// dpm($menu_link->getTitle());
$path = $menu_link->getUrlObject()->getInternalPath();
preg_match('/^(node)\/(\d+)$/', $path, $m);
// dpm($m);
if($m[1] !== "node") continue;
$nids[] = ($m[2]);
}
$this->nodes = entity_load_multiple('node', $nids);
}
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',
"#nodes_entities"=>$this->nodes,
);
}
/**
* Display productions as a page.
*
* @return renderable array
*/
public function productions() {
// $this.getProductionBlock();
return $this->toRenderable();
}
private function getProductionBlock(){
$block = \Drupal\block\Entity\Block::load('productions');
return $block;
}
/**
* Get agenda data as json through ajax.
*
* @return json
*/
public function productionsjson() {
$renderable = $this->toRenderable();
// $rendered = render($renderable);
// We can't render directly the entity as it throw an exception with cachable data
// see http://blog.dcycle.com/blog/2018-01-24/caching-drupal-8-rest-resource/#the-dreaded-leaked-metadata-error
$rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($renderable) {
return render($renderable);
});
// add menu production block
// not used anymore as production block is always present (but not visible)
// $block = $this->getProductionBlock();
// $block_render = \Drupal::entityTypeManager()
// ->getViewBuilder('block')
// ->view($block);
$data = [
'rendered'=> $rendered,
'title'=> 'Productions',
// 'block' => array(
// 'rendered'=> \Drupal::service('renderer')->renderRoot($block_render),
// 'region'=> str_replace('_', '-', $block->getRegion()),
// 'id'=> preg_replace('/^[^:]+:(.+)$/', 'block-$1', $block->getPluginId())
// )
];
// translations links
$route_name = 'edlp_productions.productions';
$links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_URL, Url::fromRoute($route_name));
if (isset($links->links)) {
$translations_build = [
'#theme' => 'links__language_block',
'#links' => $links->links,
'#attributes' => ['class' => ["language-switcher-{$links->method_id}",],],
'#set_active_class' => TRUE,
];
$translations_rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($translations_build) {return render($translations_build);});
$data ['translations_links'] = $translations_rendered;
}
$data['#cache'] = [
'max-age' => \Drupal\Core\Cache\Cache::PERMANENT,
'tags' => ['edlp-productions-cache']
];
// $response = new JsonResponse();
// $response->setData($data);
$response = new CacheableJsonResponse($data);
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($renderable));
return $response;
// return array(
// '#markup'=>'hello'
// );
}
}
@@ -0,0 +1,3 @@
{% for node in nodes %}
{{ node.build }}
{% endfor %}