diff --git a/src/TwigTweakExtension.php b/src/TwigTweakExtension.php index d007798..9d10ae5 100644 --- a/src/TwigTweakExtension.php +++ b/src/TwigTweakExtension.php @@ -65,6 +65,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']), @@ -141,12 +142,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'); + $plugin_id = $storage->load($id)->toArray()['plugin']; + $configuration['id'] = $id; + return \Drupal::service('twig_tweak.block_view_builder')->build($plugin_id, $configuration, $wrapper); + } + /** * Builds the render array of a given region. */