You are here

public function WorkbenchContentController::renderBlocks in Workbench 8

Render the registered blocks as output.

Parameters

$blocks: An array of block items formatted for rendering a view.

See also

hook_workbench_content_alter()

3 calls to WorkbenchContentController::renderBlocks()
WorkbenchContentController::allContent in src/Controller/WorkbenchContentController.php
Page callback for the workbench content page.
WorkbenchContentController::content in src/Controller/WorkbenchContentController.php
Page callback for the workbench content page.
WorkbenchContentController::editedContent in src/Controller/WorkbenchContentController.php
Page callback for the workbench content page.

File

src/Controller/WorkbenchContentController.php, line 137

Class

WorkbenchContentController
Generates the pages defined by Workbench.

Namespace

Drupal\workbench\Controller

Code

public function renderBlocks($blocks) {
  $output = [];

  // Render each block element.
  foreach ($blocks as $key => $block) {
    if (empty($block['#view_id']) || !Views::getView($block['#view_id'])) {
      $build = $block;
    }
    else {
      $view_id = $block['#view_id'];
      $display_id = $block['#view_display'];

      // Create a view embed for this content.
      $build = views_embed_view($view_id, $display_id);
    }
    if (!isset($build['#attributes'])) {
      $build['#attributes'] = $block['#attributes'];
    }
    else {
      $build['#attributes'] = array_merge_recursive($build['#attributes'], $block['#attributes']);
    }
    $output[] = $build;
  }
  return [
    'blocks' => $output,
    '#prefix' => '<div class="admin my-workbench">',
    '#suffix' => '</div>',
    '#attached' => [
      'library' => [
        'workbench/workbench.content',
      ],
    ],
  ];
}