ShibbolethLoginBlock.php in Shibboleth Authentication 8
File
src/Plugin/Block/ShibbolethLoginBlock.php
View source
<?php
namespace Drupal\shib_auth\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
class ShibbolethLoginBlock extends BlockBase {
public function build() {
$config = \Drupal::config('shib_auth.advancedsettings');
$current_user = \Drupal::currentUser();
$markup = '<div class="shibboleth-links">';
if (!$current_user
->id()) {
$markup .= '<div class="shibboleth-login">' . shib_auth_get_login_link() . '</div>';
}
else {
$markup .= '<div class="shibboleth-logout">' . shib_auth_get_logout_link() . '</div>';
}
$markup .= '</div>';
$build['shibboleth_login_block'] = [
'#markup' => $markup,
'#cache' => [
'contexts' => [
'user.roles:anonymous',
],
],
];
if (!$config
->get('url_redirect_login')) {
$build['shibboleth_login_block']['#cache']['contexts'][] = 'url.path';
$build['shibboleth_login_block']['#cache']['contexts'][] = 'url.query_args';
}
return $build;
}
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), [
'shibboleth_login_block',
]);
}
}