diff --git a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php index a384ff7..2c729f1 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php @@ -66,7 +66,7 @@ public function submitForm(array &$form, array &$form_state) { // The search form relies on control of the redirect destination for its // functionality, so we override any static destination set in the request. // See http://drupal.org/node/292565. - if (isset($this->request) && $this->request->query->has('destination')) { + if ($this->request->query->has('destination')) { $this->request->query->remove('destination'); } diff --git a/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php b/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php index d314186..b692e5e 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php +++ b/core/modules/search/lib/Drupal/search/Plugin/Block/SearchBlock.php @@ -10,7 +10,10 @@ use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\search\Form\SearchBlockForm; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Provides a 'Search form' block. @@ -21,7 +24,23 @@ * module = "search" * ) */ -class SearchBlock extends BlockBase { +class SearchBlock extends BlockBase implements ContainerFactoryPluginInterface { + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static($configuration, $plugin_id, $plugin_definition, $container->get('request')); + } + + /** + * Constructs a SearchBlock object. + */ + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Request $request) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + + $this->request = $request; + } /** * Overrides \Drupal\block\BlockBase::access(). @@ -34,7 +53,7 @@ public function access() { * {@inheritdoc} */ public function build() { - return array(drupal_get_form(new SearchBlockForm())); + // Pass the current request to drupal_get_form for use in the buildForm. + return drupal_get_form(new SearchBlockForm(), $this->request); } - }