public function ConfigPagesBlock::build in Config Pages 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/Block/ConfigPagesBlock.php \Drupal\config_pages\Plugin\Block\ConfigPagesBlock::build()
- 8 src/Plugin/Block/ConfigPagesBlock.php \Drupal\config_pages\Plugin\Block\ConfigPagesBlock::build()
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/ ConfigPagesBlock.php, line 75
Class
- ConfigPagesBlock
- Provides a generic ConfigPages block.
Namespace
Drupal\config_pages\Plugin\BlockCode
public function build() {
$config = $this
->getConfiguration();
if (!empty($config['config_page_type'])) {
$config_page = ConfigPages::config($config['config_page_type']);
if (!is_object($config_page)) {
return [];
}
$view_mode = $config['config_page_view_mode'];
$build = $this->entity_type_manager
->getViewBuilder('config_pages')
->view($config_page, $view_mode, NULL);
// Add contextual links to block.
$build['#contextual_links'] = [
'config_pages_type' => [
'route_parameters' => [
'config_pages_type' => $config['config_page_type'],
],
],
];
return $build;
}
return [];
}