Skip to content
Snippets Groups Projects
Commit ba05c740 authored by catch's avatar catch
Browse files

Issue #2497307 by Wim Leers: Search block marks itself uncacheable for no reason

parent 6eb89b52
No related branches found
No related tags found
No related merge requests found
......@@ -7,8 +7,10 @@
namespace Drupal\search\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\search\SearchPageRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -24,14 +26,34 @@ class SearchBlockForm extends FormBase {
*/
protected $searchPageRepository;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a new SearchBlockForm.
*
* @param \Drupal\search\SearchPageRepositoryInterface $search_page_repository
* The search page repository.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Render\RendererInterface
* The renderer.
*/
public function __construct(SearchPageRepositoryInterface $search_page_repository) {
public function __construct(SearchPageRepositoryInterface $search_page_repository, ConfigFactoryInterface $config_factory, RendererInterface $renderer) {
$this->searchPageRepository = $search_page_repository;
$this->configFactory = $config_factory;
$this->renderer = $renderer;
}
/**
......@@ -39,7 +61,9 @@ public function __construct(SearchPageRepositoryInterface $search_page_repositor
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('search.search_page_repository')
$container->get('search.search_page_repository'),
$container->get('config.factory'),
$container->get('renderer')
);
}
......@@ -85,6 +109,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#name' => '',
);
// SearchPageRepository::getDefaultSearchPage() depends on search.settings.
$this->renderer->addCacheableDependency($form, $this->configFactory->get('search.settings'));
return $form;
}
......
......@@ -37,13 +37,4 @@ public function build() {
return \Drupal::formBuilder()->getForm('Drupal\search\Form\SearchBlockForm');
}
/**
* {@inheritdoc}
*
* @todo Make cacheable once https://www.drupal.org/node/2351015 lands.
*/
public function getCacheMaxAge() {
return 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment