diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index 36e3004..cff1fb6 100644 --- a/src/TwigTweakExtension.php +++ b/src/TwigTweakExtension.php @@ -145,8 +145,11 @@ class TwigTweakExtension extends AbstractExtension { /** * Builds the render array for a block. */ - public static function drupalBlock(string $id, array $configuration = [], bool $wrapper = TRUE): array { - return \Drupal::service('twig_tweak.block_view_builder')->build($id, $configuration, $wrapper); + public static function drupalBlock(string $id, array $configuration = [], array | string $arguments = [] bool $wrapper = TRUE): array { + if (is_string($arguments)) { + $arguments = explode(',', $arguments); + } + return \Drupal::service('twig_tweak.block_view_builder')->build($id, $configuration, $arguments, $wrapper); } /** diff --git a/src/View/BlockViewBuilder.php b/src/View/BlockViewBuilder.php index f06fda9..e88773c 100644 --- a/src/View/BlockViewBuilder.php +++ b/src/View/BlockViewBuilder.php @@ -13,6 +13,7 @@ use Drupal\Core\Plugin\ContextAwarePluginInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\views\Plugin\Block\ViewsBlock; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -103,7 +104,7 @@ class BlockViewBuilder { * @return array * A renderable array representing the content of the block. */ - public function build(string $id, array $configuration = [], bool $wrapper = TRUE): array { + public function build(string $id, array $configuration = [], array $arguments = [], bool $wrapper = TRUE): array { $configuration += ['label_display' => BlockPluginInterface::BLOCK_LABEL_VISIBLE]; @@ -131,6 +132,15 @@ class BlockViewBuilder { } } + // Overrride contextual arguments if arguments parameter is being passed + // and the instance is of type ViewBlock + if ($block_plugin instanceof ViewsBlock) { + if (!empty($arguments)) { + $view = $block_plugin->getViewExecutable(); + $view->args = $arguments; + } + } + // Place the content returned by the block plugin into a 'content' child // element, as a way to allow the plugin to have complete control of its // properties and rendering (for instance, its own #theme) without