renderBarePage example


  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];
    $events[KernelEvents::EXCEPTION][] = ['onKernelRequestMaintenance'];
    
$regions['sidebar_first'] = $this->updateTasksList('run');
          $output = _batch_page($request);
          break;
      }
    }

    if ($output instanceof Response) {
      return $output;
    }
    $title = $output['#title'] ?? $this->t('Drupal database update');

    return $this->bareHtmlPageRenderer->renderBarePage($output$title, 'maintenance_page', $regions);
  }

  /** * Returns the info database update page. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @return array * A render array. */
  
'title' => $this->randomMachineName(12),
      ],
    ];

    $build = [];
    foreach ($urls as $feed_info) {
      $build['#attached']['feed'][] = [$feed_info['url']$feed_info['title']];
    }

    // Use the bare HTML page renderer to render our links.     $renderer = $this->container->get('bare_html_page_renderer');
    $response = $renderer->renderBarePage($build, '', 'maintenance_page');
    // Glean the content from the response object.     $this->setRawContent($response->getContent());
    // Assert that the content contains the RSS links we specified.     foreach ($urls as $description => $feed_info) {
      $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url']$feed_info['title']));
    }
  }

  /** * Creates a pattern representing the RSS feed in the page. */
  

  // We defer the display of messages until all operations are done.   $show_messages = !(($batch = batch_get()) && isset($batch['running']));
}
else {
  \Drupal::logger('access denied')->warning('authorize.php');
  $page_title = t('Access denied');
  $content = ['#markup' => t('You are not allowed to access this page.')];
}

$bare_html_page_renderer = \Drupal::service('bare_html_page_renderer');
$response = $bare_html_page_renderer->renderBarePage($content$page_title, 'maintenance_page', [
  '#show_messages' => $show_messages,
]);
if (!$is_allowed) {
  $response->setStatusCode(403);
}
$response->send();
$this->userFloodControl->register('user.failed_login_user', $flood_config->get('user_window')$flood_control_user_identifier);
      }

      if ($flood_control_triggered = $form_state->get('flood_control_triggered')) {
        if ($flood_control_triggered == 'user') {
          $message = $this->formatPlural($flood_config->get('user_limit'), 'There has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', 'There have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', [':url' => Url::fromRoute('user.pass')->toString()]);
        }
        else {
          // We did not find a uid, so the limit is IP-based.           $message = $this->t('Too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href=":url">request a new password</a>.', [':url' => Url::fromRoute('user.pass')->toString()]);
        }
        $response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $message]$this->t('Login failed'), 'maintenance_page');
        $response->setStatusCode(403);
        $form_state->setResponse($response);
      }
      else {
        // Use $form_state->getUserInput() in the error message to guarantee         // that we send exactly what the user typed in. The value from         // $form_state->getValue() may have been modified by validation         // handlers that ran earlier than this one.         $user_input = $form_state->getUserInput();
        $query = isset($user_input['name']) ? ['name' => $user_input['name']] : [];
        $form_state->setErrorByName('name', $this->t('Unrecognized username or password. <a href=":password">Forgot your password?</a>', [':password' => Url::fromRoute('user.pass', []['query' => $query])->toString()]));
        


            return $this->service;
        }

        /** * {@inheritdoc} */
        public function renderBarePage(array $content$title$page_theme_property, array $page_additions = array (
        ))
        {
            return $this->lazyLoadItself()->renderBarePage($content$title$page_theme_property$page_additions);
        }

    }

}


  /** * Tests that we get an exception when we try to attach an illegal type. */
  public function testProcessAttached() {
    // Specify invalid attachments in a render array.     $build['#attached']['library'][] = 'core/drupal.states';
    $build['#attached']['drupal_process_states'][] = [];
    $renderer = $this->container->get('bare_html_page_renderer');
    $this->expectException(\LogicException::class);
    $renderer->renderBarePage($build, '', 'maintenance_page');
  }

}

  protected function render(array &$elements) {
    // \Drupal\Core\Render\BareHtmlPageRenderer::renderBarePage calls out to     // system_page_attachments() directly.     if (!\Drupal::moduleHandler()->moduleExists('system')) {
      throw new \Exception(__METHOD__ . ' requires system module to be installed.');
    }

    // Use the bare HTML page renderer to render our links.     $renderer = $this->container->get('bare_html_page_renderer');
    $response = $renderer->renderBarePage($elements, '', 'maintenance_page');

    // Glean the content from the response object.     $content = $response->getContent();
    $this->setRawContent($content);
    return $content;
  }

  /** * Sets an in-memory Settings variable. * * @param string $name * The name of the setting to set. * @param bool|string|int|array|null $value * The value to set. Note that array values are replaced entirely; use * \Drupal\Core\Site\Settings::get() to perform custom merges. */
Home | Imprint | This part of the site doesn't use cookies.