PreviewAwareBlock.php

Same filename and directory in other branches
  1. 9 core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Block/PreviewAwareBlock.php
  2. 10 core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Block/PreviewAwareBlock.php

Namespace

Drupal\layout_builder_test\Plugin\Block

File

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

View source
<?php

declare (strict_types=1);
namespace Drupal\layout_builder_test\Plugin\Block;

use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines a class for a context-aware block.
 */
class PreviewAwareBlock extends BlockBase {
  
  /**
   * {@inheritdoc}
   */
  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,
    ];
  }

}

Classes

Title Deprecated Summary
PreviewAwareBlock Defines a class for a context-aware block.

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