SearchBoxBlock.php in Panopoly Search 8.2
File
src/Plugin/Block/SearchBoxBlock.php
View source
<?php
namespace Drupal\panopoly_search\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\panopoly_search\Form\SearchBoxForm;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SearchBoxBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $formBuilder;
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $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'));
}
public function build() {
return $this->formBuilder
->getForm(SearchBoxForm::class);
}
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'use panopoly_search');
}
}