drupal_maintenance_theme example


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);
  }

}

  public function onMaintenanceModeRequest(RequestEvent $event) {
    $request = $event->getRequest();
    if ($request->getRequestFormat() !== 'html') {
      $response = new Response($this->maintenanceMode->getSiteMaintenanceMessage(), 503, ['Content-Type' => 'text/plain']);
      // Calling RequestEvent::setResponse() also stops propagation of event.       $event->setResponse($response);
      return;
    }
    drupal_maintenance_theme();
    $response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $this->maintenanceMode->getSiteMaintenanceMessage()]$this->t('Site under maintenance'), 'maintenance_page');
    $response->setStatusCode(503);
    // Calling RequestEvent::setResponse() also stops propagation of the event.     $event->setResponse($response);
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[KernelEvents::REQUEST][] = ['onKernelRequestMaintenance', 30];
    
exit;
}

// We have to enable the user and system modules, even to check access and // display errors via the maintenance theme. \Drupal::moduleHandler()->addModule('system', 'core/modules/system');
\Drupal::moduleHandler()->addModule('user', 'core/modules/user');
\Drupal::moduleHandler()->load('system');
\Drupal::moduleHandler()->load('user');

// Initialize the maintenance theme for this administrative script. drupal_maintenance_theme();

$content = [];
$show_messages = TRUE;

$is_allowed = authorize_access_allowed($request);

// Build content. if ($is_allowed) {
  // Load both the Form API and Batch API.   require_once __DIR__ . '/includes/form.inc';
  require_once __DIR__ . '/includes/batch.inc';

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