load_block_on_ajax-8.x-1.0/src/Controller/LoadBlockController.php

src/Controller/LoadBlockController.php
<?php

namespace Drupal\load_block_on_ajax\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;
/**
 * Defines HelloController class.
 */
class LoadBlockController {

  /**
   * Display the markup.
   *
   * @return array
   *   Return markup array.
   */
    public function loadBlock( $block_machine_name ) {

      $block = \Drupal\block\Entity\Block::load($block_machine_name);
//       print_r($block->);
      $block_content = '';
      if( $block ) {
        $block_content = \Drupal::entityTypeManager()->getViewBuilder('block')->view($block);
        ($block_content);
      }

//         $block_config = \Drupal\block\Entity\Block::load($block_machine_name);
//         $uuid = $block_config->getPlugin()->getDerivativeId();
//         $block_content = \Drupal::service('entity.repository')->loadEntityByUuid('block_content', $uuid);

      return new JsonResponse(render(\Drupal::service('renderer')->renderRoot($block_content)));

  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc