Commit 993ede00 authored by catch's avatar catch
Browse files

Issue #2845743 by pwolanin, tim.plunkett, AbhishekLal, claudiu.cristea,...

Issue #2845743 by pwolanin, tim.plunkett, AbhishekLal, claudiu.cristea, alexpott: Search form needlessly extends EntityForm
parent 9cf2b355
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\RendererInterface; use Drupal\Core\Render\RendererInterface;
use Drupal\search\Form\SearchPageForm;
use Drupal\search\SearchPageInterface; use Drupal\search\SearchPageInterface;
use Drupal\search\SearchPageRepositoryInterface; use Drupal\search\SearchPageRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
...@@ -84,7 +85,7 @@ public function view(Request $request, SearchPageInterface $entity) { ...@@ -84,7 +85,7 @@ public function view(Request $request, SearchPageInterface $entity) {
} }
$build['#title'] = $plugin->suggestedTitle(); $build['#title'] = $plugin->suggestedTitle();
$build['search_form'] = $this->entityFormBuilder()->getForm($entity, 'search'); $build['search_form'] = $this->formBuilder()->getForm(SearchPageForm::class, $entity);
// Build search results, if keywords or other search parameters are in the // Build search results, if keywords or other search parameters are in the
// GET parameters. Note that we need to try the search if 'keys' is in // GET parameters. Note that we need to try the search if 'keys' is in
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
* "form" = { * "form" = {
* "add" = "Drupal\search\Form\SearchPageAddForm", * "add" = "Drupal\search\Form\SearchPageAddForm",
* "edit" = "Drupal\search\Form\SearchPageEditForm", * "edit" = "Drupal\search\Form\SearchPageEditForm",
* "search" = "Drupal\search\Form\SearchPageForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm" * "delete" = "Drupal\Core\Entity\EntityDeleteForm"
* } * }
* }, * },
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
namespace Drupal\search\Form; namespace Drupal\search\Form;
use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\search\SearchPageInterface;
/** /**
* Provides a search form for site wide search. * Provides a search form for site wide search.
...@@ -15,10 +16,10 @@ ...@@ -15,10 +16,10 @@
* trigger the search being processed by the controller, and adding in any * trigger the search being processed by the controller, and adding in any
* additional query parameters they need to execute search. * additional query parameters they need to execute search.
*/ */
class SearchPageForm extends EntityForm { class SearchPageForm extends FormBase {
/** /**
* {@inheritdoc} * The search page entity.
* *
* @var \Drupal\search\SearchPageInterface * @var \Drupal\search\SearchPageInterface
*/ */
...@@ -34,7 +35,9 @@ public function getFormId() { ...@@ -34,7 +35,9 @@ public function getFormId() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function form(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state, SearchPageInterface $search_page = NULL) {
$this->entity = $search_page;
$plugin = $this->entity->getPlugin(); $plugin = $this->entity->getPlugin();
$form_state->set('search_page_id', $this->entity->id()); $form_state->set('search_page_id', $this->entity->id());
...@@ -72,16 +75,7 @@ public function form(array $form, FormStateInterface $form_state) { ...@@ -72,16 +75,7 @@ public function form(array $form, FormStateInterface $form_state) {
// Allow the plugin to add to or alter the search form. // Allow the plugin to add to or alter the search form.
$plugin->searchFormAlter($form, $form_state); $plugin->searchFormAlter($form, $form_state);
return $form;
return parent::form($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
// The submit button is added in the form directly.
return [];
} }
/** /**
......
...@@ -110,7 +110,7 @@ public function getHelp(); ...@@ -110,7 +110,7 @@ public function getHelp();
* *
* The core search module only invokes this method on active module plugins * The core search module only invokes this method on active module plugins
* when building a form for them in * when building a form for them in
* \Drupal\search\Form\SearchPageForm::form(). A plugin implementing this * \Drupal\search\Form\SearchPageForm::buildForm(). A plugin implementing this
* will also need to implement the buildSearchUrlQuery() method. * will also need to implement the buildSearchUrlQuery() method.
* *
* @param array $form * @param array $form
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment