You are here

public function AutoBlockSchedulerController::schedulerBlockList in Auto Block Scheduler 8.2

Scheduler block list.

Return value

html The table result.

1 string reference to 'AutoBlockSchedulerController::schedulerBlockList'
auto_block_scheduler.routing.yml in ./auto_block_scheduler.routing.yml
auto_block_scheduler.routing.yml

File

src/Controller/AutoBlockSchedulerController.php, line 24

Class

AutoBlockSchedulerController
Class AutoBlockSchedulerController.

Namespace

Drupal\auto_block_scheduler\Controller

Code

public function schedulerBlockList() {
  $blocks = Block::loadMultiple();
  $current_url = Url::fromRoute('<current>');
  $destination = $current_url
    ->toString();
  $rows = [];
  $inc = 0;
  foreach ($blocks as $key => $block) {
    $settings = $block
      ->get('visibility');
    $url = Url::fromRoute('entity.block.edit_form', [
      'block' => $key,
    ], [
      'query' => [
        'destination' => $destination,
      ],
      'absolute' => TRUE,
    ]);
    if (isset($settings['auto_block_scheduler'])) {
      $rows[$inc]['id'] = $key;
      $rows[$inc]['theme'] = $block
        ->get('theme');
      $rows[$inc]['region'] = $block
        ->get('region');
      $rows[$inc]['status'] = !empty($block
        ->get('status')) ? 'Enabled' : 'Disabled';
      $rows[$inc]['label'] = $block
        ->get('settings')['label'];
      $rows[$inc]['published_on'] = !empty($settings['auto_block_scheduler']['published_on']) ? DrupalDateTime::createFromTimestamp($settings['auto_block_scheduler']['published_on']) : 'NA';
      $rows[$inc]['unpublished_on'] = !empty($settings['auto_block_scheduler']['unpublished_on']) ? DrupalDateTime::createFromTimestamp($settings['auto_block_scheduler']['unpublished_on']) : 'NA';
      $rows[$inc]['negate'] = !empty($settings['auto_block_scheduler']['negate']) ? '1' : '0';
      $rows[$inc]['configure'] = Link::fromTextAndUrl($this
        ->t('Configure'), $url);
      $inc++;
    }
  }
  return [
    '#type' => 'table',
    '#header' => [
      'id' => 'Id',
      'theme' => 'Theme',
      'region' => 'Region',
      'status' => 'Status',
      'label' => 'Label',
      'published_on' => 'Published On',
      'unpublished_on' => 'Unpublished On',
      'negate' => 'Negate',
      'operation' => 'Operation',
    ],
    '#rows' => $rows,
    "#sticky" => TRUE,
    "#empty" => "No, Block scheduled with auto block scheduler",
    '#caption' => $this
      ->t("Auto Block Scheduler"),
  ];
}