function PreviewAwareBlock::build

Same name in other branches
  1. 9 core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Block/PreviewAwareBlock.php \Drupal\layout_builder_test\Plugin\Block\PreviewAwareBlock::build()
  2. 10 core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Block/PreviewAwareBlock.php \Drupal\layout_builder_test\Plugin\Block\PreviewAwareBlock::build()

Overrides BlockPluginInterface::build

File

core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Block/PreviewAwareBlock.php, line 23

Class

PreviewAwareBlock
Defines a class for a context-aware block.

Namespace

Drupal\layout_builder_test\Plugin\Block

Code

public function build() {
    $markup = $this->t('This block is being rendered normally.');
    if ($this->inPreview) {
        $markup = $this->t('This block is being rendered in preview mode.');
    }
    return [
        '#markup' => $markup,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.