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