You are here

public function CourseOutlineBlock::build in Course 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Block/CourseOutlineBlock.php \Drupal\course\Plugin\Block\CourseOutlineBlock::build()
  2. 3.x src/Plugin/Block/CourseOutlineBlock.php \Drupal\course\Plugin\Block\CourseOutlineBlock::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/CourseOutlineBlock.php, line 35

Class

CourseOutlineBlock
Provides a course outline block.

Namespace

Drupal\course\Plugin\Block

Code

public function build() {
  $build = [];
  $build['#cache']['max-age'] = 0;
  $course = course_get_context();
  $account = Drupal::currentUser();
  if ($course && $course
    ->isEnrolled($account)) {

    // Display the configured outline handler output.

    /* @var $outlinePlugin CourseOutlinePluginBase */
    $outlinePlugin = Drupal::service('plugin.manager.course.outline')
      ->createInstance($course
      ->get('outline')
      ->getString());
    $outline = $outlinePlugin
      ->render($course, $account);
    $build['outline'] = $outline;
  }
  return $build;
}