added animation to edlp loader, created edlp_ajax_node module

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-01 13:06:19 +01:00
parent de3d9edc03
commit 432fb2367f
13 changed files with 321 additions and 67 deletions
@@ -0,0 +1,11 @@
# @Author: Bachir Soussi Chiadmi <bach>
# @Email: bachir@figureslibres.io
# @Filename: edlp_ajax_node.info.yml
# @License: GPL-V3
name: Edlp Ajax Node
type: module
description: Manage ajax node loading for edlp d8.
core: 8.x
package: Edlp
@@ -0,0 +1,21 @@
<?php
# @Author: Bachir Soussi Chiadmi <bach>
# @Email: bachir@figureslibres.io
# @Filename: edlp_ajax_node.module
# @License: GPL-V3
/**
* Implements hook_theme().
*/
function edlp_ajax_node_theme($existing, $type, $theme, $path) {
// @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
return array(
'edlp_ajax_node' => array(
'file' => 'includes/edlp_ajax_node.inc',
'variables' => array(
'node' => NULL
),
),
);
}
@@ -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_ajax_node.node:
path: '/edlp/node/{nid}'
defaults:
_controller: '\Drupal\edlp_ajax_node\Controller\EdlpAjaxNodeController::node'
_title: 'Node'
requirements:
_permission: 'access content'
edlp_ajax_node.ajaxnode:
path: '/edlp/node/{nid}/ajax'
defaults:
_controller: '\Drupal\edlp_ajax_node\Controller\EdlpAjaxNodeController::nodejson'
_title: 'AjaxNode'
requirements:
_permission: 'access content'
@@ -0,0 +1,12 @@
<?php
// use Drupal\Core\Url;
function template_preprocess_edlp_ajax_node(&$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['node'] = $view_builder->view($vars['node'], 'default');
}
@@ -0,0 +1,54 @@
<?php
namespace Drupal\edlp_ajax_node\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
class EdlpAjaxNodeController extends ControllerBase {
private function query() {
$this->node = entity_load('node', $this->nid);
}
private function toRenderable(){
$this->query();
// dpm($this->future_nodes);
return array(
"#theme"=>'edlp_ajax_node',
'#node' => $this->node,
);
}
/**
* Display node as a page.
*
* @return renderable array
*/
public function node($nid) {
$this->nid = $nid;
return $this->toRenderable();
}
/**
* Get node as json through ajax.
*
* @return json
*/
public function nodejson($nid) {
$this->nid = $nid;
$response = new JsonResponse();
$renderable = $this->toRenderable();
$rendered = render($renderable);
$response->setData([
'test'=>'hello edlp ajax node',
'nid' => $this->nid,
'rendered'=> $rendered
]);
return $response;
}
}
@@ -0,0 +1 @@
{{ node }}