usesAdminTheme example

/** * Tests search plugin annotation and interfaces. */
  public function testAnnotation() {
    /** @var \Drupal\search\SearchPluginManager $manager */
    $manager = \Drupal::service('plugin.manager.search');
    /** @var \Drupal\help_topics\Plugin\Search\HelpSearch $plugin */
    $plugin = $manager->createInstance('help_search');
    $this->assertInstanceOf(AccessibleInterface::class$plugin);
    $this->assertInstanceOf(SearchIndexingInterface::class$plugin);
    $this->assertSame('Help', (string) $plugin->getPluginDefinition()['title']);
    $this->assertTrue($plugin->usesAdminTheme());
  }

}
'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();
      // Make sure help plugin rendered help link.       $path_help = $path . '/help';
      $session->linkByHrefExists($path_help);
      $this->assertSame($use_admin_theme$plugin->usesAdminTheme());
      $this->assertAdminTheme($use_admin_theme);
      // Make sure that search help also rendered in admin theme.       $this->drupalGet($path_help);
      $this->assertAdminTheme($use_admin_theme);
    }
  }

  /** * Asserts whether an administrative theme's used for the loaded page. * * @param bool $is_admin * TRUE to test for administrative theme, FALSE otherwise. * * @internal */
'_entity_access' => 'entity.view',
          '_permission' => 'search content',
        ],
        [
          'parameters' => [
            'entity' => [
              'type' => 'entity:search_page',
            ],
          ],
        ]
      );
      if ($entity->getPlugin()->usesAdminTheme()) {
        $routes["search.view_$entity_id"]->setOption('_admin_route', TRUE);
        $routes["search.help_$entity_id"]->setOption('_admin_route', TRUE);
      }
    }
    return $routes;
  }

}
Home | Imprint | This part of the site doesn't use cookies.