You are here

public function BlockShortcode::process in Shortcode 2.0.x

Same name and namespace in other branches
  1. 8 shortcode_basic_tags/src/Plugin/Shortcode/BlockShortcode.php \Drupal\shortcode_basic_tags\Plugin\Shortcode\BlockShortcode::process()

Performs the shortcode processing.

Parameters

array $attributes: Array of attributes.

string $text: The text string to be processed.

string $langcode: The language code of the text to be filtered. Defaults to LANGCODE_NOT_SPECIFIED.

Return value

string The processed text.

Overrides ShortcodeInterface::process

File

shortcode_basic_tags/src/Plugin/Shortcode/BlockShortcode.php, line 79

Class

BlockShortcode
Insert a custom block to the text.

Namespace

Drupal\shortcode_basic_tags\Plugin\Shortcode

Code

public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {

  // Merge with default attributes.
  $attributes = $this
    ->getAttributes([
    'id' => '',
    'view' => 'full',
  ], $attributes);
  if ((int) $attributes['id']) {
    $block_entity = BlockContent::load($attributes['id']);
    if ($block_entity) {
      $block_view = $this->entityTypeManager
        ->getViewBuilder('block_content')
        ->view($block_entity, $attributes['view']);
      if ($block_view) {
        return $this->renderer
          ->render($block_view);
      }
    }
  }
}