public function RenderedSiteSettingsBlock::build in Site Settings and Labels 8
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.
Overrides BlockPluginInterface::build
File
- src/
Plugin/ Block/ RenderedSiteSettingsBlock.php, line 110
Class
- RenderedSiteSettingsBlock
- Provides a 'RenderedSiteSettingsBlock' block.
Namespace
Drupal\site_settings\Plugin\BlockCode
public function build() {
$build = [];
$entities = $this->entityTypeManager
->getStorage('site_setting_entity')
->loadByProperties([
'type' => $this->configuration['setting'],
]);
if (empty($entities)) {
return $build;
}
$view_builder = $this->entityTypeManager
->getViewBuilder('site_setting_entity');
// Loop through the entities and their fields.
foreach ($entities as $entity) {
$pre_render = $view_builder
->view($entity, 'default');
$render_output = render($pre_render);
$build[] = [
'#markup' => $render_output,
];
}
return $build;
}