diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index 36e3004..d0efce5 100644 --- a/src/TwigTweakExtension.php +++ b/src/TwigTweakExtension.php @@ -66,6 +66,7 @@ class TwigTweakExtension extends AbstractExtension { new TwigFunction('drupal_view', 'views_embed_view'), new TwigFunction('drupal_view_result', 'views_get_view_result'), new TwigFunction('drupal_block', [self::class, 'drupalBlock']), + new TwigFunction('drupal_block_by_id', [self::class, 'drupalBlockById']), new TwigFunction('drupal_region', [self::class, 'drupalRegion']), new TwigFunction('drupal_entity', [self::class, 'drupalEntity']), new TwigFunction('drupal_entity_form', [self::class, 'drupalEntityForm']), @@ -143,12 +144,22 @@ class TwigTweakExtension extends AbstractExtension { } /** - * Builds the render array for a block. + * Builds the render array for a block identified by plugin. */ public static function drupalBlock(string $id, array $configuration = [], bool $wrapper = TRUE): array { return \Drupal::service('twig_tweak.block_view_builder')->build($id, $configuration, $wrapper); } + /** + * Builds the render array for the block identified by id. + */ + public static function drupalBlockById($id, array $configuration = [], bool $wrapper = TRUE) { + $storage = \Drupal::entityTypeManager()->getStorage('block'); + $block = $storage->load($id)->toArray(); + $configuration = array_merge($block['settings'], $configuration); + return \Drupal::service('twig_tweak.block_view_builder')->build($block['plugin'], $configuration, $wrapper); + } + /** * Builds the render array of a given region. */