public function StepsBlock::build in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Plugin/Block/StepsBlock.php \Drupal\opigno_learning_path\Plugin\Block\StepsBlock::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/ StepsBlock.php, line 90
Class
- StepsBlock
- Provides a 'article' block.
Namespace
Drupal\opigno_learning_path\Plugin\BlockCode
public function build() {
$group = $this
->getGroupByRouteOrContext();
$steps = $this
->getStepsByGroup($group);
// Get group context.
$cid = $this
->getCurrentGroupContentId();
if (!$cid) {
return [];
}
if (!$steps) {
return [];
}
$steps = array_values($steps);
if (!$steps) {
return [];
}
foreach ($steps as $index => &$step) {
$step['step_previous'] = $steps[$index - 1] ?? FALSE;
$step['step_first'] = $index === 0;
$step['step_last'] = count($steps) - 1 === $index;
}
return [
'#type' => 'container',
[
'#theme' => 'opigno_lp_step_activity',
'title' => [
'#markup' => $group
->label(),
],
'steps' => $steps,
'#pre_render' => [
[
$this,
'processModuleList',
],
],
],
];
}