public function QuickNodeBlock::build in Quick Node Block 8
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ QuickNodeBlock.php, line 235
Class
- QuickNodeBlock
- Provides a Node Block with his display.
Namespace
Drupal\quick_node_block\Plugin\BlockCode
public function build() {
$build = [];
$config = $this
->getConfiguration();
if (preg_match("/.+\\s\\(([^\\)]+)\\)/", $config['quick_node'], $matches)) {
$nid = $matches[1];
$view_mode = $config['quick_display'];
$entity_type = 'node';
$view_builder = $this->entityTypeManager
->getViewBuilder($entity_type);
$storage = $this->entityTypeManager
->getStorage($entity_type);
if ($node = $storage
->load($nid)) {
$build = $view_builder
->view($node, $view_mode);
}
}
return $build;
}