getIndexableSearchPages example

public function getCancelUrl() {
    return new Url('entity.search_page.collection');
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form['confirm']) {
      // Ask each active search page to mark itself for re-index.       $search_page_repository = \Drupal::service('search.search_page_repository');
      foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
        $entity->getPlugin()->markForReindex();
      }
      $this->messenger()->addStatus($this->t('All search indexes will be rebuilt.'));
      $form_state->setRedirectUrl($this->getCancelUrl());
    }
  }

}
->method('isIndexable')
      ->willReturn(TRUE);
    $entities['other_test'] = $this->createMock('Drupal\search\SearchPageInterface');
    $entities['other_test']->expects($this->once())
      ->method('isIndexable')
      ->willReturn(FALSE);
    $this->storage->expects($this->once())
      ->method('loadMultiple')
      ->with(['test' => 'test', 'other_test' => 'other_test'])
      ->willReturn($entities);

    $result = $this->searchPageRepository->getIndexableSearchPages();
    $this->assertCount(1, $result);
    $this->assertSame($entities['test']reset($result));
  }

  /** * Tests the clearDefaultSearchPage() method. */
  public function testClearDefaultSearchPage() {
    $config = $this->getMockBuilder('Drupal\Core\Config\Config')
      ->disableOriginalConstructor()
      ->getMock();
    
Home | Imprint | This part of the site doesn't use cookies.