public function WebformAccessGroupEntityBlock::build in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_access/src/Plugin/Block/WebformAccessGroupEntityBlock.php \Drupal\webform_access\Plugin\Block\WebformAccessGroupEntityBlock::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
- modules/
webform_access/ src/ Plugin/ Block/ WebformAccessGroupEntityBlock.php, line 85
Class
- WebformAccessGroupEntityBlock
- Provides a 'webform_access_group_entity' block.
Namespace
Drupal\webform_access\Plugin\BlockCode
public function build() {
/** @var \Drupal\node\NodeInterface[] $nodes */
$nodes = $this->webformAccessGroupStorage
->getUserEntities($this->currentUser, 'node');
if (empty($nodes)) {
return NULL;
}
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$items = [];
foreach ($nodes as $node) {
if ($node
->access()) {
if ($node
->hasTranslation($langcode)) {
$node = $node
->getTranslation($langcode);
}
$items[] = $node
->toLink()
->toRenderable();
}
}
if (empty($items)) {
return NULL;
}
return [
'#theme' => 'item_list',
'#items' => $items,
];
}