OpenIDConnectLoginBlock.php in OpenID Connect / OAuth client 2.x
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 Symfony\Component\DependencyInjection\ContainerInterface;
class OpenIDConnectLoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $formBuilder;
public function __construct(array $configuration, string $plugin_id, $plugin_definition, FormBuilder $form_builder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$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('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');
}
}