ClearCookieBlock.php in Close Block 8
File
src/Plugin/Block/ClearCookieBlock.php
View source
<?php
namespace Drupal\closeblock\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ClearCookieBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $formBuilder;
protected $currentUser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, $formBuilder, $currentUser) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formBuilder = $formBuilder;
$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('form_builder'), $container
->get('current_user'));
}
public function build() {
$form = $this->formBuilder
->getForm('Drupal\\closeblock\\Form\\CloseBlockClearCookieForm');
$build['closeblock_block'] = [
'#theme' => 'custom_block_closeblock',
'#content' => $form,
];
return $build;
}
public function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, $this->currentUser
->hasPermission('close block'));
}
}