Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\search\Plugin\Derivative;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
|
Chris@0
|
6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
Chris@0
|
7 use Drupal\search\SearchPageRepositoryInterface;
|
Chris@0
|
8 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Provides local tasks for each search page.
|
Chris@0
|
12 */
|
Chris@0
|
13 class SearchLocalTask extends DeriverBase implements ContainerDeriverInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The search page repository.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var \Drupal\search\SearchPageRepositoryInterface
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $searchPageRepository;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Constructs a new SearchLocalTask.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @param \Drupal\search\SearchPageRepositoryInterface $search_page_repository
|
Chris@0
|
26 * The search page repository.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function __construct(SearchPageRepositoryInterface $search_page_repository) {
|
Chris@0
|
29 $this->searchPageRepository = $search_page_repository;
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * {@inheritdoc}
|
Chris@0
|
34 */
|
Chris@0
|
35 public static function create(ContainerInterface $container, $base_plugin_id) {
|
Chris@0
|
36 return new static(
|
Chris@0
|
37 $container->get('search.search_page_repository')
|
Chris@0
|
38 );
|
Chris@0
|
39 }
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * {@inheritdoc}
|
Chris@0
|
43 */
|
Chris@0
|
44 public function getDerivativeDefinitions($base_plugin_definition) {
|
Chris@0
|
45 $this->derivatives = [];
|
Chris@0
|
46
|
Chris@0
|
47 if ($default = $this->searchPageRepository->getDefaultSearchPage()) {
|
Chris@0
|
48 $active_search_pages = $this->searchPageRepository->getActiveSearchPages();
|
Chris@0
|
49 foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) {
|
Chris@0
|
50 $this->derivatives[$entity_id] = [
|
Chris@0
|
51 'title' => $entity->label(),
|
Chris@0
|
52 'route_name' => 'search.view_' . $entity_id,
|
Chris@0
|
53 'base_route' => 'search.plugins:' . $default,
|
Chris@0
|
54 'weight' => $entity->getWeight(),
|
Chris@0
|
55 ];
|
Chris@0
|
56 }
|
Chris@0
|
57 }
|
Chris@0
|
58 return $this->derivatives;
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 }
|