SocialAuthLoginBlock.php in Social Auth 8
File
src/Plugin/Block/SocialAuthLoginBlock.php
View source
<?php
namespace Drupal\social_auth\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SocialAuthLoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
private $socialAuthConfig;
public function __construct(array $configuration, $plugin_id, $plugin_definition, ImmutableConfig $social_auth_config) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->socialAuthConfig = $social_auth_config;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory')
->get('social_auth.settings'));
}
public function build() {
return array(
'#theme' => 'login_with',
'#social_networks' => $this->socialAuthConfig
->get('auth'),
);
}
public function blockAccess(AccountInterface $account) {
if ($account
->isAnonymous()) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}
}