public function DocumentsLastGroupBlock::build in Opigno Learning path 3.x
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/ DocumentsLastGroupBlock.php, line 27
Class
- DocumentsLastGroupBlock
- Provides a documentslastgroupblock block.
Namespace
Drupal\opigno_learning_path\Plugin\BlockCode
public function build() {
$this->groupId = $gid = $this->configuration["group"];
$tid = _tft_get_group_tid($gid);
$content = _tft_folder_content($tid, FALSE, $gid);
$content = array_slice($content ?: [], 0, 4);
foreach ($content as $index => $item) {
$content[$index] = [
'#theme' => 'opigno_documents_last_group_item',
'#type' => $item["type"] == 'file' ? 'file' : 'folder',
'#item' => $item,
'#label' => $item["name"],
'#link' => $this
->itemLink($item),
];
}
$build['content'] = [
'#theme' => 'opigno_documents_last_group_block',
'content' => $content,
];
return $build;
}