You are here

public function TfaTrustedBrowserSetup::getOverview in Two-factor Authentication (TFA) 8

Plugin overview page.

Parameters

array $params: Parameters to setup the overview information.

Return value

array The overview form.

Overrides TfaSetupInterface::getOverview

File

src/Plugin/TfaSetup/TfaTrustedBrowserSetup.php, line 192

Class

TfaTrustedBrowserSetup
TFA Trusted Browser Setup Plugin.

Namespace

Drupal\tfa\Plugin\TfaSetup

Code

public function getOverview(array $params) {
  $trusted_browsers = [];
  foreach ($this
    ->getTrustedBrowsers() as $device) {
    $date_formatter = \Drupal::service('date.formatter');
    $vars = [
      '@set' => $date_formatter
        ->format($device['created']),
      '@browser' => $device['name'],
    ];
    if (empty($device['last_used'])) {
      $message = $this
        ->t('@browser, set @set', $vars);
    }
    else {
      $vars['@time'] = $date_formatter
        ->format($device['last_used']);
      $message = $this
        ->t('@browser, set @set, last used @time', $vars);
    }
    $trusted_browsers[] = $message;
  }
  $output = [
    'heading' => [
      '#type' => 'html_tag',
      '#tag' => 'h3',
      '#value' => $this
        ->t('Trusted browsers'),
    ],
    'description' => [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this
        ->t('Browsers that will not require a verification code during login.'),
    ],
  ];
  if (!empty($trusted_browsers)) {
    $output['list'] = [
      '#theme' => 'item_list',
      '#items' => $trusted_browsers,
      '#title' => $this
        ->t('Browsers that will not require a verification code during login.'),
    ];
  }
  $output['link'] = [
    '#theme' => 'links',
    '#links' => [
      'admin' => [
        'title' => 'Configure Trusted Browsers',
        'url' => Url::fromRoute('tfa.validation.setup', [
          'user' => $params['account']
            ->id(),
          'method' => $params['plugin_id'],
        ]),
      ],
    ],
  ];
  return $output;
}