hasActiveTheme example

public function specificSuggestionAlter() {
    return ['#theme' => 'theme_test_specific_suggestions__variant'];
  }

  /** * Controller to ensure that no theme is initialized. * * @return \Symfony\Component\HttpFoundation\JsonResponse * The json response with the theme initialized information. */
  public function nonHtml() {
    $theme_initialized = \Drupal::theme()->hasActiveTheme();
    return new JsonResponse(['theme_initialized' => $theme_initialized]);
  }

  /** * Controller for testing preprocess functions with theme suggestions. */
  public function preprocessSuggestions() {
    return [
      [
        '#theme' => 'theme_test_preprocess_suggestions',
        '#foo' => 'suggestion',
      ],
class MaintenanceThemeTest extends KernelTestBase {

  /** * Tests that the maintenance theme initializes the theme and its base themes. */
  public function testMaintenanceTheme() {
    $this->setSetting('maintenance_theme', 'test_subtheme');
    // Get the maintenance theme loaded.     drupal_maintenance_theme();

    // Do we have an active theme?     $this->assertTrue(\Drupal::theme()->hasActiveTheme());

    $active_theme = \Drupal::theme()->getActiveTheme();
    $this->assertEquals('test_subtheme', $active_theme->getName());

    $base_themes = $active_theme->getBaseThemeExtensions();
    $base_theme_names = array_keys($base_themes);
    $this->assertSame(['test_basetheme']$base_theme_names);
  }

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