PreviewAwareBlock.php in Drupal 10
File
core/modules/layout_builder/tests/modules/layout_builder_test/src/Plugin/Block/PreviewAwareBlock.php
View source
<?php
namespace Drupal\layout_builder_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
class PreviewAwareBlock extends BlockBase {
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,
];
}
}