diff --git a/core/modules/node/config/search.page.node_search.yml b/core/modules/node/config/search.page.node_search.yml index 6df728c..cf0de1f 100644 --- a/core/modules/node/config/search.page.node_search.yml +++ b/core/modules/node/config/search.page.node_search.yml @@ -1,10 +1,9 @@ id: node_search -label: 'Node search' +label: 'Content' uuid: 25687eeb-4bb5-469c-ad05-5eb24cd7012c status: true langcode: en path: node -title: Content weight: -10 plugin: node_search configuration: { } diff --git a/core/modules/search/config/schema/search.schema.yml b/core/modules/search/config/schema/search.schema.yml index f587ab4..68e6877 100644 --- a/core/modules/search/config/schema/search.schema.yml +++ b/core/modules/search/config/schema/search.schema.yml @@ -86,9 +86,6 @@ search.page.*: path: type: string label: 'Search page path' - title: - type: label - label: 'Tab title' weight: type: integer label: 'Weight' diff --git a/core/modules/search/lib/Drupal/search/Entity/SearchPage.php b/core/modules/search/lib/Drupal/search/Entity/SearchPage.php index e235d7a..9834477 100644 --- a/core/modules/search/lib/Drupal/search/Entity/SearchPage.php +++ b/core/modules/search/lib/Drupal/search/Entity/SearchPage.php @@ -92,13 +92,6 @@ class SearchPage extends ConfigEntityBase implements SearchPageInterface { protected $path; /** - * The title of the search page. - * - * @var string - */ - protected $title; - - /** * The weight of the search page. * * @var int @@ -153,13 +146,6 @@ public function isDefaultSearch() { /** * {@inheritdoc} */ - public function getTitle() { - return $this->title; - } - - /** - * {@inheritdoc} - */ public function getPath() { return $this->path; } @@ -178,7 +164,6 @@ public function getExportProperties() { $properties = parent::getExportProperties(); $names = array( 'path', - 'title', 'weight', 'plugin', 'configuration', diff --git a/core/modules/search/lib/Drupal/search/Form/SearchPageAddForm.php b/core/modules/search/lib/Drupal/search/Form/SearchPageAddForm.php index 6d25909..bf8a089 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchPageAddForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchPageAddForm.php @@ -19,7 +19,6 @@ public function buildForm(array $form, array &$form_state, $search_plugin_id = N $this->entity->setPlugin($search_plugin_id); $definition = $this->entity->getPlugin()->getPluginDefinition(); $this->entity->set('label', $definition['title']); - $this->entity->set('title', $definition['title']); return parent::buildForm($form, $form_state); } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php b/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php index 8e10f05..e263be1 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php @@ -79,7 +79,7 @@ public function form(array $form, array &$form_state) { $form['label'] = array( '#type' => 'textfield', '#title' => $this->t('Label'), - '#description' => $this->t('The administrative label for this search page.'), + '#description' => $this->t('The label for this search page.'), '#default_value' => $this->entity->label(), '#maxlength' => '255', ); @@ -93,13 +93,6 @@ public function form(array $form, array &$form_state) { 'exists' => array($this, 'exists'), ), ); - $form['title'] = array( - '#type' => 'textfield', - '#title' => $this->t('Tab title'), - '#description' => $this->t('The title presented to the user, usually as a tab on the search page.'), - '#default_value' => $this->entity->getTitle(), - '#maxlength' => '255', - ); $form['path'] = array( '#type' => 'textfield', '#title' => $this->t('Path'), diff --git a/core/modules/search/lib/Drupal/search/Plugin/Derivative/SearchLocalTask.php b/core/modules/search/lib/Drupal/search/Plugin/Derivative/SearchLocalTask.php index 2bf5e17..c4fb104 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/Derivative/SearchLocalTask.php +++ b/core/modules/search/lib/Drupal/search/Plugin/Derivative/SearchLocalTask.php @@ -50,9 +50,10 @@ public function getDerivativeDefinitions(array $base_plugin_definition) { $this->derivatives = array(); if ($default = $this->searchPageRepository->getDefaultSearchPage()) { - foreach ($this->searchPageRepository->getActiveSearchPages() as $entity_id => $entity) { + $active_search_pages = $this->searchPageRepository->getActiveSearchPages(); + foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) { $this->derivatives[$entity_id] = array( - 'title' => $entity->getTitle(), + 'title' => $entity->label(), 'route_name' => 'search.view_' . $entity_id, 'tab_root_id' => 'search.plugins:' . $default, 'weight' => $entity->getWeight(), diff --git a/core/modules/search/lib/Drupal/search/Routing/SearchPluginRoutes.php b/core/modules/search/lib/Drupal/search/Routing/SearchPluginRoutes.php index 75fb614..1378ecd 100644 --- a/core/modules/search/lib/Drupal/search/Routing/SearchPluginRoutes.php +++ b/core/modules/search/lib/Drupal/search/Routing/SearchPluginRoutes.php @@ -80,7 +80,7 @@ public function routes() { '/search/' . $entity->getPath() . '/{keys}', array( '_content' => 'Drupal\search\Controller\SearchController::view', - '_title' => $entity->getTitle(), + '_title' => $entity->label(), 'entity' => $entity_id, 'keys' => '', ), diff --git a/core/modules/search/lib/Drupal/search/SearchPageInterface.php b/core/modules/search/lib/Drupal/search/SearchPageInterface.php index 1ebfa7f..7b40280 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageInterface.php +++ b/core/modules/search/lib/Drupal/search/SearchPageInterface.php @@ -52,11 +52,6 @@ public function isIndexable(); public function getPath(); /** - * @return string - */ - public function getTitle(); - - /** * @return int */ public function getWeight(); diff --git a/core/modules/search/lib/Drupal/search/SearchPageRepository.php b/core/modules/search/lib/Drupal/search/SearchPageRepository.php index 32b1cdd..1c917ea 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageRepository.php +++ b/core/modules/search/lib/Drupal/search/SearchPageRepository.php @@ -98,6 +98,15 @@ public function clearDefaultSearchPage() { } /** + * {@inheritdoc} + */ + public function sortSearchPages($search_pages) { + $entity_info = $this->storage->entityInfo(); + uasort($search_pages, array($entity_info['class'], 'sort')); + return $search_pages; + } + + /** * Returns an entity query instance. * * @return \Drupal\Core\Entity\Query\QueryInterface diff --git a/core/modules/search/lib/Drupal/search/SearchPageRepositoryInterface.php b/core/modules/search/lib/Drupal/search/SearchPageRepositoryInterface.php index 697d797..5eb8e26 100644 --- a/core/modules/search/lib/Drupal/search/SearchPageRepositoryInterface.php +++ b/core/modules/search/lib/Drupal/search/SearchPageRepositoryInterface.php @@ -49,4 +49,15 @@ public function getDefaultSearchPage(); */ public function clearDefaultSearchPage(); + /** + * Sorts a list of search pages. + * + * @param \Drupal\search\SearchPageInterface[] $search_pages + * The unsorted list of search pages. + * + * @return \Drupal\search\SearchPageInterface[] + * The sorted list of search pages. + */ + public function sortSearchPages($search_pages); + } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php index 9aca5c9..43af6f2 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php @@ -134,9 +134,8 @@ function testSearchModuleSettingsPage() { * Verifies that you can disable individual search plugins. */ function testSearchModuleDisabling() { - // Array of search plugins to test: 'path' is the search path, 'title' is - // the tab title, 'keys' are the keywords to search for, and 'text' is - // the text to assert is on the results page. + // Array of search plugins to test: 'keys' are the keywords to search for, + // and 'text' is the text to assert is on the results page. $plugin_info = array( 'node_search' => array( 'keys' => 'pizza', @@ -170,14 +169,14 @@ function testSearchModuleDisabling() { $info = $plugin_info[$entity_id]; $this->drupalGet('search/' . $entity->getPath() . '/' . $info['keys']); $this->assertResponse(200); - $this->assertNoText('no results', $entity->getTitle() . ' search found results'); + $this->assertNoText('no results', $entity->label() . ' search found results'); $this->assertText($info['text'], 'Correct search text found'); - // Verify that other plugin search tab titles are not visible. + // Verify that other plugin search tab labels are not visible. foreach ($plugins as $other) { if ($other != $entity_id) { - $title = $entities[$other]->getTitle(); - $this->assertNoText($title, $title . ' search tab is not shown'); + $label = $entities[$other]->label(); + $this->assertNoText($label, $label . ' search tab is not shown'); } } @@ -210,8 +209,8 @@ function testSearchModuleDisabling() { foreach (array('search/node/pizza', 'search/node') as $path) { $this->drupalGet($path); foreach ($plugins as $entity_id) { - $title = $entities[$entity_id]->getTitle(); - $this->assertText($title, format_string('%title search tab is shown', array('%title' => $title))); + $label = $entities[$entity_id]->label(); + $this->assertText($label, format_string('%label search tab is shown', array('%label' => $label))); } } } @@ -249,7 +248,6 @@ public function testMultipleSearchPages() { $first = array(); $first['label'] = $this->randomString(); $first_id = $first['id'] = strtolower($this->randomName(8)); - $first['title'] = $this->randomString(); $first['path'] = strtolower($this->randomName(8)); $this->drupalPostForm(NULL, $first, t('Add search page')); $this->assertDefaultSearch($first_id, 'The default page matches the only search page.'); @@ -262,7 +260,6 @@ public function testMultipleSearchPages() { $edit = array(); $edit['label'] = $this->randomString(); $edit['id'] = strtolower($this->randomName(8)); - $edit['title'] = $this->randomString(); $edit['path'] = $first['path']; $this->drupalPostForm(NULL, $edit, t('Add search page')); $this->assertText(t('The search path must be unique.')); @@ -271,7 +268,6 @@ public function testMultipleSearchPages() { $second = array(); $second['label'] = $this->randomString(); $second_id = $second['id'] = strtolower($this->randomName(8)); - $second['title'] = $this->randomString(); $second['path'] = strtolower($this->randomName(8)); $this->drupalPostForm(NULL, $second, t('Add search page')); $this->assertDefaultSearch($first_id, 'The default page matches the only search page.'); diff --git a/core/modules/search/tests/Drupal/search/Tests/SearchPageRepositoryTest.php b/core/modules/search/tests/Drupal/search/Tests/SearchPageRepositoryTest.php index 51307a8..d56a67d 100644 --- a/core/modules/search/tests/Drupal/search/Tests/SearchPageRepositoryTest.php +++ b/core/modules/search/tests/Drupal/search/Tests/SearchPageRepositoryTest.php @@ -7,6 +7,7 @@ namespace Drupal\search\Tests; +use Drupal\search\Entity\SearchPage; use Drupal\search\SearchPageRepository; use Drupal\Tests\UnitTestCase; @@ -229,4 +230,37 @@ public function testGetDefaultSearchPageWithInactiveDefault() { $this->assertSame('test', $this->searchPageRepository->getDefaultSearchPage()); } + /** + * Tests the sortSearchPages() method. + */ + public function testSortSearchPages() { + $this->storage->expects($this->once()) + ->method('entityInfo') + ->will($this->returnValue(array('class' => 'Drupal\search\Tests\TestSearchPage'))); + + // Declare entities out of their expected order so we can be sure they were + // sorted. We cannot mock these because of uasort(), see + // https://bugs.php.net/bug.php?id=50688. + $unsorted_entities['test4'] = new TestSearchPage(array('weight' => 0, 'status' => FALSE, 'label' => 'Test4')); + $unsorted_entities['test3'] = new TestSearchPage(array('weight' => 10, 'status' => TRUE, 'label' => 'Test3')); + $unsorted_entities['test2'] = new TestSearchPage(array('weight' => 0, 'status' => TRUE, 'label' => 'Test2')); + $unsorted_entities['test1'] = new TestSearchPage(array('weight' => 0, 'status' => TRUE, 'label' => 'Test1')); + $expected = $unsorted_entities; + ksort($expected); + + $sorted_entities = $this->searchPageRepository->sortSearchPages($unsorted_entities); + $this->assertSame($expected, $sorted_entities); + } + +} + +class TestSearchPage extends SearchPage { + public function __construct(array $values) { + foreach ($values as $key => $value) { + $this->$key = $value; + } + } + public function label($langcode = NULL) { + return $this->label; + } } diff --git a/core/modules/search/tests/modules/search_extra_type/config/search.page.dummy_search_type.yml b/core/modules/search/tests/modules/search_extra_type/config/search.page.dummy_search_type.yml index b8ace9a..e60478c 100644 --- a/core/modules/search/tests/modules/search_extra_type/config/search.page.dummy_search_type.yml +++ b/core/modules/search/tests/modules/search_extra_type/config/search.page.dummy_search_type.yml @@ -4,6 +4,5 @@ uuid: b55858d4-f428-474c-8200-ef47a4597aef status: true langcode: en path: dummy_path -title: 'Dummy search type' plugin: search_extra_type_search configuration: { } diff --git a/core/modules/user/config/search.page.user_search.yml b/core/modules/user/config/search.page.user_search.yml index e1de395..4823ec4 100644 --- a/core/modules/user/config/search.page.user_search.yml +++ b/core/modules/user/config/search.page.user_search.yml @@ -1,9 +1,8 @@ id: user_search -label: 'User search' +label: 'Users' uuid: c0d6b9a7-09a7-415f-b71a-26957bef635c status: true langcode: en path: user -title: Users plugin: user_search configuration: { }