You are here

protected function BlockVisibilityGroupedListBuilder::buildBlocksForm in Block Visibility Groups 8

Builds the main "Blocks" portion of the form.

Return value

array

Overrides BlockListBuilder::buildBlocksForm

File

src/BlockVisibilityGroupedListBuilder.php, line 229

Class

BlockVisibilityGroupedListBuilder
Extends BlockListBuilder to add our elements only show certain blocks.

Namespace

Drupal\block_visibility_groups

Code

protected function buildBlocksForm() {
  $form = parent::buildBlocksForm();
  $show_global_in_group = $this
    ->getShowGlobalWithGroup();
  if ($block_visibility_group = $this
    ->getBlockVisibilityGroup(TRUE)) {
    foreach ($form as &$row_info) {
      if (isset($row_info['title']['#url'])) {

        /** @var \Drupal\Core\Url $url */
        $url = $row_info['title']['#url'];
        $query = $url
          ->getOption('query');
        $url = Url::fromRoute('block_visibility_groups.admin_library', [
          'theme' => $this
            ->getThemeName(),
          'block_visibility_group' => $block_visibility_group,
        ], [
          'query' => $query,
        ]);
        $row_info['title']['#url'] = $url;

        // $query['block_visibility_group'] = $this->getBlockVisibilityGroup();
        // $url->setOption('query', $query);.
      }
      if (isset($row_info['operations']['#links']) && $row_info['operations']['#links']) {
        foreach ($row_info['operations']['#links'] as &$op_info) {
          $url = $op_info['url'];
          $query = $url
            ->getOption('query');
          $query['block_visibility_group'] = $block_visibility_group;
          $url
            ->setOption('query', $query);
        }
      }
    }
  }

  // If viewing all blocks, add a column indicating the visibility group.
  if ($this
    ->getBlockVisibilityGroup() == static::ALL_GROUP || $block_visibility_group && $show_global_in_group) {
    $this
      ->addGroupColumn($form);
  }
  return $form;
}