setDefaultSearchPage example

/** * Sets the search page as the default. * * @param \Drupal\search\SearchPageInterface $search_page * The search page entity. * * @return \Symfony\Component\HttpFoundation\RedirectResponse * A redirect to the search settings page. */
  public function setAsDefault(SearchPageInterface $search_page) {
    // Set the default page to this search page.     $this->searchPageRepository->setDefaultSearchPage($search_page);

    $this->messenger()->addStatus($this->t('The default search page is now %label. Be sure to check the ordering of your search pages.', ['%label' => $search_page->label()]));
    return $this->redirect('entity.search_page.collection');
  }

}
$actions = parent::actions($form$form_state);
    $actions['submit']['#value'] = $this->t('Save');
    return $actions;
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    // If there is no default search page, make the added search the default.     if (!$this->searchPageRepository->getDefaultSearchPage()) {
      $this->searchPageRepository->setDefaultSearchPage($this->entity);
    }

    parent::save($form$form_state);

    $this->messenger()->addStatus($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));
  }

}
$search_page = $this->createMock('Drupal\search\SearchPageInterface');
    $search_page->expects($this->once())
      ->method('id')
      ->willReturn($id);
    $search_page->expects($this->once())
      ->method('enable')
      ->willReturn($search_page);
    $search_page->expects($this->once())
      ->method('save')
      ->willReturn($search_page);
    $this->searchPageRepository->setDefaultSearchPage($search_page);
  }

  /** * Tests the sortSearchPages() method. */
  public function testSortSearchPages() {
    $entity_type = $this->createMock('Drupal\Core\Entity\EntityTypeInterface');
    $entity_type->expects($this->any())
      ->method('getClass')
      ->willReturn('Drupal\Tests\search\Unit\TestSearchPage');
    $this->storage->expects($this->once())
      
Home | Imprint | This part of the site doesn't use cookies.