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

8.0.x
Nathaniel Catchpole 2015-06-01 16:23:24 +01:00
parent 6eb89b52b8
commit ba05c7401d
2 changed files with 29 additions and 11 deletions

View File

@ -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 @@ class SearchBlockForm extends FormBase {
*/
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 @@ class SearchBlockForm extends FormBase {
'#name' => '',
);
// SearchPageRepository::getDefaultSearchPage() depends on search.settings.
$this->renderer->addCacheableDependency($form, $this->configFactory->get('search.settings'));
return $form;
}

View File

@ -37,13 +37,4 @@ class SearchBlock extends BlockBase {
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;
}
}