added productions menu block to ajax load

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-03 12:55:15 +01:00
parent 55f5d5b2f0
commit b1598ae231
5 changed files with 166 additions and 53 deletions
@@ -9,8 +9,6 @@ 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
@@ -42,8 +40,6 @@ class ProductionsController extends ControllerBase {
$this->nodes = entity_load_multiple('node', $nids);
// TODO: apply right display
}
@@ -66,9 +62,17 @@ class ProductionsController extends ControllerBase {
* @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.
*
@@ -80,11 +84,21 @@ class ProductionsController extends ControllerBase {
$renderable = $this->toRenderable();
$rendered = render($renderable);
// TODO: add menu production block
// add menu production block
$block = $this->getProductionBlock();
$block_render = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
$response->setData([
'test'=>'hello',
'rendered'=> $rendered
'rendered'=> $rendered,
'block' => array(
'rendered'=> \Drupal::service('renderer')->renderRoot($block_render),
'region'=> str_replace('_', '-', $block->getRegion()),
'id'=> preg_replace('/^[^:]+:(.+)$/', 'block-$1', $block->getPluginId())
)
]);
return $response;