OpenIDConnectLoginBlock.php in OpenID Connect / OAuth client 8
File
src/Plugin/Block/OpenIDConnectLoginBlock.php
View source
<?php
namespace Drupal\openid_connect\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormBuilder;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\openid_connect\Plugin\OpenIDConnectClientManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OpenIDConnectLoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $pluginManager;
protected $formBuilder;
public function __construct(array $configuration, $plugin_id, $plugin_definition, OpenIDConnectClientManager $plugin_manager, FormBuilder $form_builder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->pluginManager = $plugin_manager;
$this->formBuilder = $form_builder;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.openid_connect_client'), $container
->get('form_builder'));
}
protected function blockAccess(AccountInterface $account) {
if ($account
->isAnonymous()) {
return AccessResult::allowed()
->addCacheContexts([
'user.roles:anonymous',
]);
}
return AccessResult::forbidden();
}
public function build() {
return $this->formBuilder
->getForm('Drupal\\openid_connect\\Form\\OpenIDConnectLoginForm');
}
}