You are here

SearchBoxBlock.php in Panopoly 8.2

File

modules/panopoly/panopoly_search/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;

/**
 * Block that displays the search box.
 *
 * @Block(
 *   id = "panopoly_search_box",
 *   admin_label = @Translation("Search box (Panopoly)"),
 *   category = @Translation("Content")
 * )
 */
class SearchBoxBlock extends BlockBase implements ContainerFactoryPluginInterface {

  /**
   * The form builder.
   *
   * @var \Drupal\Core\Form\FormBuilderInterface
   */
  protected $formBuilder;

  /**
   * Constructs a new EntityView.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
   *   The form builder.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $form_builder) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->formBuilder = $form_builder;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('form_builder'));
  }

  /**
   * {@inheritdoc}
   */
  public function build() {
    return $this->formBuilder
      ->getForm(SearchBoxForm::class);
  }

  /**
   * {@inheritdoc}
   */
  protected function blockAccess(AccountInterface $account) {
    return AccessResult::allowedIfHasPermission($account, 'use panopoly_search');
  }

}

Classes

Namesort descending Description
SearchBoxBlock Block that displays the search box.