You are here

public function SiteVerifyController::verificationsListPage in Site verification 8

Controller content callback: Verifications List page.

Return value

string Render Array

1 string reference to 'SiteVerifyController::verificationsListPage'
site_verify.routing.yml in ./site_verify.routing.yml
site_verify.routing.yml

File

src/Controller/SiteVerifyController.php, line 25

Class

SiteVerifyController
Returns responses for Site Verify module routes.

Namespace

Drupal\site_verify\Controller

Code

public function verificationsListPage() {

  // $build['verifications_list'] = array(
  // '#markup' => $this->t('TODO: show list of verifications.'),
  // );
  \Drupal::service('router.builder')
    ->rebuild();
  $engines = \Drupal::service('site_verify_service')
    ->siteVerifyGetEngines();
  $destination = \Drupal::destination()
    ->getAsArray();
  $header = [
    [
      'data' => $this
        ->t('Engine'),
      'field' => 'engine',
    ],
    [
      'data' => $this
        ->t('Meta tag'),
      'field' => 'meta',
    ],
    [
      'data' => $this
        ->t('File'),
      'field' => 'file',
    ],
    [
      'data' => $this
        ->t('Operations'),
    ],
  ];
  $verifications = \Drupal::database()
    ->select('site_verify', 'sv')
    ->fields('sv')
    ->execute();
  $rows = [];
  foreach ($verifications as $verification) {
    $row = [
      'data' => [],
    ];
    $row['data'][] = $engines[$verification->engine]['name'];
    $row['data'][] = $verification->meta ? $this
      ->t('Yes') : $this
      ->t('No');
    $row['data'][] = $verification->file ? Link::fromTextAndUrl($verification->file, Url::fromRoute('site_verify.' . $verification->file)) : $this
      ->t('None');
    $operations = [];
    $operations['edit'] = [
      'title' => $this
        ->t('Edit'),
      'url' => Url::fromRoute('site_verify.verification_edit', [
        'site_verify' => $verification->svid,
      ]),
      'query' => $destination,
    ];
    $operations['delete'] = [
      'title' => $this
        ->t('Delete'),
      'url' => Url::fromRoute('site_verify.verification_delete', [
        'site_verify' => $verification->svid,
      ]),
      'query' => $destination,
    ];
    $row['data']['operations'] = [
      'data' => [
        '#theme' => 'links',
        '#links' => $operations,
        '#attributes' => [
          'class' => [
            'links',
            'inline',
          ],
        ],
      ],
    ];
    $rows[] = $row;
  }
  $build['verification_table'] = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No verifications available. <a href="@add">Add verification</a>.', [
      '@add' => Url::fromRoute('site_verify.verification_add')
        ->toString(),
    ]),
  ];

  // $build['verification_pager'] = array('#theme' => 'pager');
  return $build;
}