Browse Source

Add drupal_block_by_id() function

merge-requests/37/head
Juan Olalla 2 years ago
parent
commit
b874c2b476
  1. 13
      src/TwigTweakExtension.php

13
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.
*/

Loading…
Cancel
Save