Loading block_ajax.module +13 −2 Original line number Diff line number Diff line Loading @@ -83,12 +83,23 @@ function block_ajax_block_view_alter(array &$build, BlockPluginInterface $block) // Pre-render block. $build['#pre_render'] = [ function ($build) use ($ajaxBlocksService, $blockConfig) { // Make sure we have block and id exists. if (isset($build['#block']) && $blockId = $build['#block']->id()) { $blockId = NULL; // Use id from embedded block object. if (isset($build['#block'])) { $blockId = $build['#block']->id(); // Remove the block entity from the render array, to ensure that // blocks can be rendered without the block config entity. unset($build['#block']); } // Use id from block configuration. if (empty($blockId) && !empty($blockConfig['id'])) { $blockId = $blockConfig['id']; } // Make sure we have block id. if ($blockId) { // Add block configuration. $build['#block_settings'] = $blockConfig; Loading src/Controller/AjaxBlockController.php +42 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\block_ajax\Controller; use Drupal\block\BlockInterface; use Drupal\block_ajax\BlockViewBuilder; use Drupal\Component\Utility\Xss; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\block_ajax\Response\AjaxBlockResponse; Loading Loading @@ -185,6 +186,43 @@ class AjaxBlockController extends ControllerBase { $response->setSharedMaxAge($max_age); } /** * Get block configuration. * * @param \Symfony\Component\HttpFoundation\Request $request * The request. * * @return array * The merged and sanitized configuration. */ protected function getBlockConfiguration(Request $request): array { // The default configuration. $configuration = $request->get('config', []); // Filter/sanitize configuration data. return $this->filterConfiguration($configuration); } /** * Get filtered block configuration data. * * @param array $data * The configuration data. * * @return array * The filtered configuration data. */ protected function filterConfiguration(array $data): array { foreach ($data as $key => $value) { if (is_array($value)) { $this->filterConfiguration($value); } else { $data[$key] = Xss::filter($value); } } return $data; } /** * Implements ajax block update request handler. * Loading Loading @@ -214,7 +252,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading @@ -269,7 +307,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading @@ -326,7 +364,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading @@ -383,7 +421,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading
block_ajax.module +13 −2 Original line number Diff line number Diff line Loading @@ -83,12 +83,23 @@ function block_ajax_block_view_alter(array &$build, BlockPluginInterface $block) // Pre-render block. $build['#pre_render'] = [ function ($build) use ($ajaxBlocksService, $blockConfig) { // Make sure we have block and id exists. if (isset($build['#block']) && $blockId = $build['#block']->id()) { $blockId = NULL; // Use id from embedded block object. if (isset($build['#block'])) { $blockId = $build['#block']->id(); // Remove the block entity from the render array, to ensure that // blocks can be rendered without the block config entity. unset($build['#block']); } // Use id from block configuration. if (empty($blockId) && !empty($blockConfig['id'])) { $blockId = $blockConfig['id']; } // Make sure we have block id. if ($blockId) { // Add block configuration. $build['#block_settings'] = $blockConfig; Loading
src/Controller/AjaxBlockController.php +42 −4 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\block_ajax\Controller; use Drupal\block\BlockInterface; use Drupal\block_ajax\BlockViewBuilder; use Drupal\Component\Utility\Xss; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\block_ajax\Response\AjaxBlockResponse; Loading Loading @@ -185,6 +186,43 @@ class AjaxBlockController extends ControllerBase { $response->setSharedMaxAge($max_age); } /** * Get block configuration. * * @param \Symfony\Component\HttpFoundation\Request $request * The request. * * @return array * The merged and sanitized configuration. */ protected function getBlockConfiguration(Request $request): array { // The default configuration. $configuration = $request->get('config', []); // Filter/sanitize configuration data. return $this->filterConfiguration($configuration); } /** * Get filtered block configuration data. * * @param array $data * The configuration data. * * @return array * The filtered configuration data. */ protected function filterConfiguration(array $data): array { foreach ($data as $key => $value) { if (is_array($value)) { $this->filterConfiguration($value); } else { $data[$key] = Xss::filter($value); } } return $data; } /** * Implements ajax block update request handler. * Loading Loading @@ -214,7 +252,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading @@ -269,7 +307,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading @@ -326,7 +364,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading Loading @@ -383,7 +421,7 @@ class AjaxBlockController extends ControllerBase { } // Block configuration. $configuration = $request->get('config', []); $configuration = $this->getBlockConfiguration($request); // Get block instance. if ($blockInstance = $this->getBlockInstance($request, $block_id, $configuration)) { Loading