public function CourseNavigationBlock::build in Course 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/Block/CourseNavigationBlock.php \Drupal\course\Plugin\Block\CourseNavigationBlock::build()
- 3.x src/Plugin/Block/CourseNavigationBlock.php \Drupal\course\Plugin\Block\CourseNavigationBlock::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/ CourseNavigationBlock.php, line 34
Class
- CourseNavigationBlock
- Provides a course navigation block.
Namespace
Drupal\course\Plugin\BlockCode
public function build() {
$build['#cache']['max-age'] = 0;
$course = course_get_context();
$account = \Drupal::currentUser();
if ($course && $course
->isEnrolled($account)) {
$links = $course
->getNavigation($account);
$items = array();
foreach ($links as $key => $value) {
$items[] = array(
'#class' => array(
'course-nav-' . $key,
),
'#markup' => $value
->toString(),
);
}
// Add javascript poller to update the next step button.
$build['nav']['#attached']['library'][] = 'course/nav';
$build['nav'] = [
'#theme' => 'item_list',
'#items' => $items,
'#title' => '',
'#type' => 'ul',
'#attributes' => array(
'id' => 'course-nav',
),
];
}
return $build;
}