getActiveSearchPages example

'_permission' => 'search content',
        ],
        [
          'parameters' => [
            'entity' => [
              'type' => 'entity:search_page',
            ],
          ],
        ]
      );
    }
    $active_pages = $this->searchPageRepository->getActiveSearchPages();
    foreach ($active_pages as $entity_id => $entity) {
      $routes["search.view_$entity_id"] = new Route(
        '/search/' . $entity->getPath(),
        [
          '_controller' => 'Drupal\search\Controller\SearchController::view',
          '_title' => 'Search',
          'entity' => $entity_id,
        ],
        [
          '_entity_access' => 'entity.view',
          '_permission' => 'search content',
        ],
->method('execute')
      ->willReturn(['test' => 'test', 'other_test' => 'other_test']);

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

    $result = $this->searchPageRepository->getActiveSearchPages();
    $this->assertSame($entities$result);
  }

  /** * Tests the isSearchActive() method. */
  public function testIsSearchActive() {
    $this->query->expects($this->once())
      ->method('condition')
      ->with('status', TRUE)
      ->willReturn($this->query);
    
public function isSearchActive() {
    return (bool) $this->getQuery()
      ->condition('status', TRUE)
      ->range(0, 1)
      ->execute();
  }

  /** * {@inheritdoc} */
  public function getIndexableSearchPages() {
    return array_filter($this->getActiveSearchPages()function DSearchPageInterface $search) {
      return $search->isIndexable();
    });
  }

  /** * {@inheritdoc} */
  public function getDefaultSearchPage() {
    // Find all active search pages (without loading them).     $search_pages = $this->getQuery()
      ->condition('status', TRUE)
      
'filter' => [
        'id' => 'node_access',
        'help' => $this->t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
      ],
    ];

    // Add search table, fields, filters, etc., but only if a page using the     // node_search plugin is enabled.     if (\Drupal::moduleHandler()->moduleExists('search')) {
      $enabled = FALSE;
      $search_page_repository = \Drupal::service('search.search_page_repository');
      foreach ($search_page_repository->getActiveSearchPages() as $page) {
        if ($page->getPlugin()->getPluginId() == 'node_search') {
          $enabled = TRUE;
          break;
        }
      }

      if ($enabled) {
        $data['node_search_index']['table']['group'] = $this->t('Search');

        // Automatically join to the node table (or actually, node_field_data).         // Use a Views table alias to allow other modules to use this table too,
$container->get('search.search_page_repository')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    if ($default = $this->searchPageRepository->getDefaultSearchPage()) {
      $active_search_pages = $this->searchPageRepository->getActiveSearchPages();
      foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) {
        $this->derivatives[$entity_id] = [
          'title' => $entity->label(),
          'route_name' => 'search.view_' . $entity_id,
          'base_route' => 'search.plugins:' . $default,
          'weight' => $entity->getWeight(),
        ];
      }
    }
    return $this->derivatives;
  }

}
'page_id' => '',
    ];
  }

  /** * {@inheritdoc} */
  public function blockForm($form, FormStateInterface $form_state) {
    // The configuration for this block is which search page to connect the     // form to. Options are all configured/active search pages.     $options = [];
    $active_search_pages = $this->searchPageRepository->getActiveSearchPages();
    foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) {
      $options[$entity_id] = $entity->label();
    }

    $form['page_id'] = [
      '#type' => 'select',
      '#title' => $this->t('Search page'),
      '#description' => $this->t('The search page that the form submits to, or Default for the default search page.'),
      '#default_value' => $this->configuration['page_id'],
      '#options' => $options,
      '#empty_option' => $this->t('Default'),
      
/** * Tests that search results could be displayed in administration theme. * * @see \Drupal\node\Plugin\Search\NodeSearch * @see \Drupal\search_extra_type\Plugin\Search\SearchExtraTypeSearch * @see \Drupal\user\Plugin\Search\UserSearch */
  public function testSearchUsingAdminTheme() {
    /** @var \Drupal\search\SearchPageRepositoryInterface $repository */
    $repository = \Drupal::service('search.search_page_repository');
    $pages = $repository->getActiveSearchPages();
    // Test default configured pages.     $page_ids = [
      'node_search' => FALSE,
      'dummy_search_type' => TRUE,
      'user_search' => FALSE,
    ];
    foreach ($page_ids as $page_id => $use_admin_theme) {
      $plugin = $pages[$page_id]->getPlugin();
      $path = 'search/' . $pages[$page_id]->getPath();
      $this->drupalGet($path);
      $session = $this->assertSession();
      
Home | Imprint | This part of the site doesn't use cookies.