You are here

public function ViewBlockBase::build in Content Planner 8

Build the block and return a renderable array.

Return value

array The render array for the block.

Overrides DashboardBlockBase::build

File

src/Plugin/DashboardBlock/ViewBlockBase.php, line 30

Class

ViewBlockBase
Class ViewBlockBase.

Namespace

Drupal\content_planner\Plugin\DashboardBlock

Code

public function build() {
  $content = [];
  $config = $this
    ->getConfiguration();

  // Get view from config.
  $view_config = $this
    ->getCustomConfigByKey($config, $this->blockID);

  // Syntax is view_id.display_id.
  $view_array = explode('.', $view_config);
  if ($view_array && is_array($view_array) && isset($view_array[0]) && isset($view_array[1])) {
    $view_id = $view_array[0];
    $view_display_id = $view_array[1];
    $view = Views::getView($view_id);
    if (is_object($view)) {
      $content = $view
        ->render($view_display_id);
    }
  }
  return $content;
}