#1107: first light_home then async load full home, do not aggregate nor preprocess theme js libraries
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Drupal\Core\Url;
|
||||
|
||||
function template_preprocess_materio_home(&$vars){
|
||||
$node_view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
|
||||
$vm = "default";
|
||||
$fpnode = $vars['frontpage_node'];
|
||||
$nvb_fpnode = $node_view_builder->view($fpnode, $vm);
|
||||
$vars['frontpage_node'] = $nvb_fpnode;
|
||||
|
||||
}
|
@@ -24,6 +24,9 @@ use Drupal\mymodule\Plugin\Field\FieldType\MyFieldComputed;
|
||||
|
||||
// $field_map_kv_store->set('node', $node_map);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implement hook_entity_bundle_field_info().
|
||||
*
|
||||
@@ -136,6 +139,48 @@ function materio_home_entity_base_field_info_alter(&$fields, EntityTypeInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*
|
||||
* Register a module or theme's theme implementations.
|
||||
* The implementations declared by this hook specify how a particular render array is to be rendered as HTML.
|
||||
*
|
||||
* See: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme/8.2.x
|
||||
*
|
||||
* If you change this method, clear theme registry and routing table 'drush cc theme-registry' and 'drush cc router'.
|
||||
*/
|
||||
function materio_home_theme($existing, $type, $theme, $path) {
|
||||
|
||||
return [
|
||||
// Name of the theme hook. This is used in the controller to trigger the hook.
|
||||
'materio_home' => [
|
||||
'render element' => 'element',
|
||||
// If no template name is defined here, it defaults to the name of the theme hook, ie. module-name-theme-hook.html.twig
|
||||
'template' => 'materio-home',
|
||||
// Optionally define path to Twig template files. Defaults to the module's ./templates/ directory.
|
||||
// 'path' => $path . '/templates',
|
||||
// Optionally define variables that will be passed to the Twig template and set default values for them.
|
||||
// 'variables' => [
|
||||
// 'variable1' => 'Yet another default text.',
|
||||
// 'variable2' => 0,
|
||||
// 'variable3' => [0, 0, 0],
|
||||
// ],
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_materio_home(&$vars){
|
||||
$node_view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
$element = $vars['element'];
|
||||
$vm = $element['#view_mode'];
|
||||
$fpnode = $element['#frontpage_node'];
|
||||
$nvb_fpnode = $node_view_builder->view($fpnode, $vm);
|
||||
$vars['frontpage_node'] = $nvb_fpnode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_cron().
|
||||
*
|
||||
|
@@ -1,3 +1,11 @@
|
||||
materio_home.home:
|
||||
path: 'home'
|
||||
defaults:
|
||||
_controller: '\Drupal\materio_home\Controller\HomeController::home'
|
||||
_title: 'Home'
|
||||
requirements:
|
||||
_permission: 'access content'
|
||||
|
||||
materio_home.ajax_home:
|
||||
path: 'materio_home/ajax/gethome'
|
||||
defaults:
|
||||
|
@@ -74,14 +74,18 @@ class AjaxHomeController extends ControllerBase {
|
||||
*/
|
||||
public function getHome() {
|
||||
|
||||
$path = \Drupal::config('system.site')->get('page.front');
|
||||
// $path = \Drupal::config('system.site')->get('page.front');
|
||||
// $params = Url::fromUri("internal:" . $path)->getRouteParameters();
|
||||
// $entity_type = key($params);
|
||||
// $entity = $this->entityTypeManager()->getStorage($entity_type)->load($params[$entity_type]);
|
||||
|
||||
$params = Url::fromUri("internal:" . $path)->getRouteParameters();
|
||||
$entity_type = key($params);
|
||||
$entity = $this->entityTypeManager()->getStorage($entity_type)->load($params[$entity_type]);
|
||||
$nid = 1;
|
||||
// TODO: home nid should be a setting
|
||||
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
$node = $node_storage->load($nid);
|
||||
|
||||
$view_builder = $this->entityTypeManager()->getViewBuilder('node');
|
||||
$renderable = $view_builder->view($entity, 'default');
|
||||
$renderable = $view_builder->view($node, 'home_full');
|
||||
$rendered = $this->renderer->executeInRenderContext(new RenderContext(), function () use ($renderable) {
|
||||
return render($renderable);
|
||||
});
|
||||
|
@@ -3,15 +3,15 @@
|
||||
namespace Drupal\materio_home\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\workflow\Entity\WorkflowManager;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
// use Drupal\Core\Datetime\DrupalDateTime;
|
||||
// use Drupal\taxonomy\Entity\Term;
|
||||
// use Drupal\workflow\Entity\WorkflowManager;
|
||||
// use Drupal\Core\Url;
|
||||
// use Drupal\Core\Language\LanguageInterface;
|
||||
// use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Drupal\Core\Cache\CacheableJsonResponse;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\core\render\RenderContext;
|
||||
// use Drupal\Core\Cache\CacheableJsonResponse;
|
||||
// use Drupal\Core\Cache\CacheableMetadata;
|
||||
// use Drupal\core\render\RenderContext;
|
||||
|
||||
|
||||
|
||||
@@ -23,20 +23,24 @@ class HomeController extends ControllerBase {
|
||||
* @return renderable array
|
||||
*/
|
||||
public function home() {
|
||||
|
||||
// return "Hello";
|
||||
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
|
||||
$contents = array("#theme"=>'materio_home');
|
||||
|
||||
// presentation
|
||||
$query = \Drupal::entityQuery('node')
|
||||
->condition('status', 1)
|
||||
->condition('nid', 19990);
|
||||
// TODO: présentation nid should be a setting
|
||||
// // presentation
|
||||
// $query = \Drupal::entityQuery('node')
|
||||
// // ->condition('status', 1)
|
||||
// ->condition('nid', 1);
|
||||
// $nids = $query->execute();
|
||||
|
||||
$pres_nid = $query->execute();
|
||||
$contents["#frontpage_node"] = entity_load('node', array_pop($pres_nid));
|
||||
$nid = 1;
|
||||
// TODO: home nid should be a setting
|
||||
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
$node = $node_storage->load($nid);
|
||||
|
||||
$contents["#frontpage_node"] = $node;
|
||||
$contents["#view_mode"] = "home_light";
|
||||
return $contents;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user