You are here

public function AdministerPanelPages::build in Total Control Admin Dashboard 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/Block/AdministerPanelPages.php \Drupal\total_control\Plugin\Block\AdministerPanelPages::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/AdministerPanelPages.php, line 112

Class

AdministerPanelPages
Provides a 'Administer Panel Pages'.

Namespace

Drupal\total_control\Plugin\Block

Code

public function build() {
  if (!$this->moduleHandler
    ->moduleExists('page_manager_ui')) {
    $you_have_to_enable_text = $this
      ->t('You have to enable');
    $page_manager_ui_text = $this
      ->t('Page Manager UI');
    $to_see_this_block_text = $this
      ->t('module to see this block.');
    $markup_data = '<p>' . $you_have_to_enable_text . ' <strong>' . $page_manager_ui_text . '</strong> ' . $to_see_this_block_text . '</p>';
    return [
      '#type' => 'markup',
      '#markup' => $markup_data,
    ];
  }
  $panels = $this->entityTypeManager
    ->getStorage('page')
    ->loadMultiple();
  $header = [
    [
      'data' => $this
        ->t('Page'),
    ],
    [
      'data' => $this
        ->t('Operations'),
      'colspan' => 2,
    ],
  ];
  $destination = $this->redirectDestination
    ->getAsArray();
  $options = [
    $destination,
  ];
  foreach ($panels as $panel) {
    $rows[] = [
      'data' => [
        $panel
          ->get('label'),
        Link::fromTextAndUrl($this
          ->t('Edit'), new Url('entity.page.edit_form', [
          'machine_name' => $panel
            ->get('id'),
          'step' => 'general',
          'options' => $options,
        ]))
          ->toString(),
        Link::fromTextAndUrl($this
          ->t('Disable'), new Url('entity.page.disable', [
          'page' => $panel
            ->get('id'),
          'options' => $options,
        ]))
          ->toString(),
      ],
    ];
  }
  $link = NULL;
  if ($this->currentUser
    ->hasPermission('administer pages')) {
    $link = Link::fromTextAndUrl($this
      ->t('Page manager administration'), new Url('entity.page.collection'));
  }
  $body_data = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  ];
  $markup_data = $this->renderer
    ->render($body_data);
  if ($link instanceof RenderableInterface) {
    $markup_data .= $link
      ->toString();
  }
  return [
    '#type' => 'markup',
    '#markup' => $markup_data,
  ];
}