FancyLoginBlock.php in Fancy Login 3.0.x
File
src/Plugin/Block/FancyLoginBlock.php
View source
<?php
namespace Drupal\fancy_login\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FancyLoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $currentUser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $currentUser) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $currentUser;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'));
}
public function build() {
if ($this->currentUser
->isAnonymous() || !empty($GLOBALS['menu_admin'])) {
$url = Url::fromRoute('user.login');
return [
'link' => [
'#markup' => Link::fromTextAndUrl($this
->t('Login'), $url)
->toString(),
'#prefix' => '<div id="fancy_login_login_link_wrapper">',
'#suffix' => '</div>',
],
];
}
}
}