SocialAuthLoginBlock.php in Social Auth 3.x
File
src/Plugin/Block/SocialAuthLoginBlock.php
View source
<?php
namespace Drupal\social_auth\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\social_api\Plugin\NetworkManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SocialAuthLoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
private $networkManager;
private $socialAuthConfig;
public function __construct(array $configuration, string $plugin_id, $plugin_definition, ImmutableConfig $social_auth_config, NetworkManager $network_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->networkManager = $network_manager;
$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'), $container
->get('plugin.network.manager'));
}
public function build() {
$networks = $this->networkManager
->getDefinitions();
$social_networks = $this->socialAuthConfig
->get('auth');
foreach ($social_networks as $id => &$social_network) {
$social_network['name'] = NULL;
if (isset($networks[$id]) && isset($networks[$id]['social_network'])) {
$social_network['name'] = $networks[$id]['social_network'];
}
}
return [
'#theme' => 'login_with',
'#social_networks' => $social_networks,
];
}
}