diff --git a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php index bf987e6..b2758de 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -16,6 +16,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\Language\Language; +use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\AccessibleInterface; use Drupal\Core\Database\Query\Condition; @@ -34,7 +35,7 @@ * path = "node" * ) */ -class NodeSearch extends SearchPluginBase implements AccessibleInterface, SearchIndexingInterface { +class NodeSearch extends SearchPluginBase implements AccessibleInterface, SearchIndexingInterface, PluginFormInterface { /** * A database connection object. @@ -516,7 +517,7 @@ public function searchFormSubmit(array &$form, array &$form_state) { /** * {@inheritdoc} */ - public function addToAdminForm(array &$form, array &$form_state) { + public function buildConfigurationForm(array $form, array &$form_state) { // Output form for defining rank factor weights. $form['content_ranking'] = array( '#type' => 'details', @@ -537,12 +538,19 @@ public function addToAdminForm(array &$form, array &$form_state) { '#default_value' => variable_get('node_rank_' . $var, 0), ); } + return $form; } /** * {@inheritdoc} */ - public function submitAdminForm(array &$form, array &$form_state) { + public function validateConfigurationForm(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, array &$form_state) { foreach ($this->moduleHandler->invokeAll('ranking') as $var => $values) { if (isset($form_state['values']['node_rank_' . $var])) { // @todo Fix when https://drupal.org/node/1831632 is in. diff --git a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php index d07e346..45f1e09 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php @@ -11,6 +11,7 @@ use Drupal\Core\Extension\ModuleHandler; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\Plugin\PluginFormInterface; use Drupal\search\SearchPluginManager; use Drupal\system\SystemConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -196,7 +197,9 @@ public function buildForm(array $form, array &$form_state) { // Per plugin settings. foreach ($active_plugins as $plugin) { - $plugin->addToAdminForm($form, $form_state); + if ($plugin instanceof PluginFormInterface) { + $form = $plugin->buildConfigurationForm($form, $form_state); + } } // Set #submit so we are sure it's invoked even if one of // the active search plugins added its own #submit. @@ -219,6 +222,12 @@ public function validateForm(array &$form, array &$form_state) { form_set_error('default_plugin', t('Your default search plugin is not selected as an active plugin.')); } } + // Handle per-plugin validation logic. + foreach ($this->searchPluginManager->getActivePlugins() as $plugin) { + if ($plugin instanceof PluginFormInterface) { + $plugin->validateConfigurationForm($form, $form_state); + } + } } /** @@ -239,7 +248,9 @@ public function submitForm(array &$form, array &$form_state) { // Handle per-plugin submission logic. foreach ($this->searchPluginManager->getActivePlugins() as $plugin) { - $plugin->submitAdminForm($form, $form_state); + if ($plugin instanceof PluginFormInterface) { + $plugin->submitConfigurationForm($form, $form_state); + } } // Check whether we are resetting the values. diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php b/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php index b1429b0..21478fe 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchInterface.php @@ -98,32 +98,4 @@ public function buildResults(); */ public function searchFormAlter(array &$form, array &$form_state); - /** - * Adds elements to the search settings form. - * - * The core search module only invokes this method on active module plugins. - * - * @param array $form - * Nested array of form elements that comprise the form. - * @param array $form_state - * A keyed array containing the current state of the form. The arguments - * that drupal_get_form() was originally called with are available in the - * array $form_state['build_info']['args']. - */ - public function addToAdminForm(array &$form, array &$form_state); - - /** - * Handles any submission for elements on the search settings form. - * - * The core search module only invokes this method on active module plugins. - * - * @param array $form - * Nested array of form elements that comprise the form. - * @param array $form_state - * A keyed array containing the current state of the form. The arguments - * that drupal_get_form() was originally called with are available in the - * array $form_state['build_info']['args']. - */ - public function submitAdminForm(array &$form, array &$form_state); - } diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php index 3b2b162..120d8bd 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php @@ -94,18 +94,4 @@ public function searchFormAlter(array &$form, array &$form_state) { // Empty default implementation. } - /** - * {@inheritdoc} - */ - public function addToAdminForm(array &$form, array &$form_state) { - // Empty default implementation. - } - - /** - * {@inheritdoc} - */ - public function submitAdminForm(array &$form, array &$form_state) { - // Empty default implementation. - } - } diff --git a/core/modules/search/tests/modules/search_extra_type/lib/Drupal/search_extra_type/Plugin/Search/SearchExtraTypeSearch.php b/core/modules/search/tests/modules/search_extra_type/lib/Drupal/search_extra_type/Plugin/Search/SearchExtraTypeSearch.php index 9b40e45..2ea35eb 100644 --- a/core/modules/search/tests/modules/search_extra_type/lib/Drupal/search_extra_type/Plugin/Search/SearchExtraTypeSearch.php +++ b/core/modules/search/tests/modules/search_extra_type/lib/Drupal/search_extra_type/Plugin/Search/SearchExtraTypeSearch.php @@ -9,6 +9,7 @@ use Drupal\Core\Annotation\Translation; use Drupal\Core\Config\Config; +use Drupal\Core\Plugin\PluginFormInterface; use Drupal\search\Plugin\SearchPluginBase; use Drupal\search\Annotation\SearchPlugin; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -22,7 +23,7 @@ * path = "dummy_path" * ) */ -class SearchExtraTypeSearch extends SearchPluginBase { +class SearchExtraTypeSearch extends SearchPluginBase implements PluginFormInterface { /** * @var \Drupal\Core\Config\Config @@ -124,7 +125,7 @@ public function buildResults() { /** * {@inheritdoc} */ - public function addToAdminForm(array &$form, array &$form_state) { + public function buildConfigurationForm(array $form, array &$form_state) { // Output form for defining rank factor weights. $form['extra_type_settings'] = array( '#type' => 'fieldset', @@ -141,12 +142,19 @@ public function addToAdminForm(array &$form, array &$form_state) { ), '#default_value' => $this->configSettings->get('boost'), ); + return $form; } /** * {@inheritdoc} */ - public function submitAdminForm(array &$form, array &$form_state) { + public function validateConfigurationForm(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, array &$form_state) { $this->configSettings ->set('boost', $form_state['values']['extra_type_settings']['boost']) ->save();