Unverified Commit ee5a8e78 authored by Alex Pott's avatar Alex Pott
Browse files

feat: #3559628 Allow #[MapQueryParameter] attribute for query string handling in controllers

By: longwave
By: alexpott
(cherry picked from commit 43c2d5ec)
parent 58d66871
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -959,7 +959,7 @@ services:
    arguments: ['@event_dispatcher', '@controller_resolver', '@request_stack', '@http_kernel.controller.argument_resolver', true]
  http_kernel.controller.argument_resolver:
    class: Symfony\Component\HttpKernel\Controller\ArgumentResolver
    arguments: ['@http_kernel.controller.argument_metadata_factory', ['@argument_resolver.request_attribute', '@argument_resolver.request', '@argument_resolver.psr7_request', '@argument_resolver.route_match', '@argument_resolver.default']]
    arguments: ['@http_kernel.controller.argument_metadata_factory', ['@argument_resolver.request_attribute', '@argument_resolver.request', '@argument_resolver.psr7_request', '@argument_resolver.route_match', '@argument_resolver.query_parameter', '@argument_resolver.default']]
  Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface: '@http_kernel.controller.argument_resolver'
  http_kernel.controller.argument_metadata_factory:
    class: Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory
@@ -981,6 +981,9 @@ services:
  argument_resolver.default:
    class: Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver
    public: false
  argument_resolver.query_parameter:
    class: Symfony\Component\HttpKernel\Controller\ArgumentResolver\QueryParameterValueResolver
    public: false
  http_middleware.content_length:
    class: Drupal\Core\StackMiddleware\ContentLength
    tags:
+82 −110
Original line number Diff line number Diff line
@@ -11,8 +11,7 @@
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Extension\ThemeInstallerInterface;
use Drupal\system\Form\ThemeExperimentalConfirmForm;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;

/**
 * Controller for theme handling.
@@ -62,21 +61,15 @@ public function __construct(ThemeHandlerInterface $theme_handler, ThemeExtension
  /**
   * Uninstalls a theme.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   A request object containing a theme name and a valid token.
   * @param string $theme
   *   The theme name.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse
   *   Redirects back to the appearance admin page.
   *
   * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
   *   Throws access denied when no theme or token is set in the request or when
   *   the token is invalid.
   */
  public function uninstall(Request $request) {
    $theme = $request->query->get('theme');
  public function uninstall(#[MapQueryParameter] string $theme) {
    $config = $this->config('system.theme');

    if (isset($theme)) {
    // Get current list of themes.
    $themes = $this->themeHandler->listInfo();

@@ -98,27 +91,17 @@ public function uninstall(Request $request) {
    return $this->redirect('system.themes_page');
  }

    throw new AccessDeniedHttpException();
  }

  /**
   * Installs a theme.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   A request object containing a theme name and a valid token.
   * @param string $theme
   *   The theme name.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse|array
   *   Redirects back to the appearance admin page or the confirmation form
   *   if an experimental theme will be installed.
   *
   * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
   *   Throws access denied when no theme or token is set in the request or when
   *   the token is invalid.
   */
  public function install(Request $request) {
    $theme = $request->query->get('theme');

    if (isset($theme)) {
  public function install(#[MapQueryParameter] string $theme) {
    // Display confirmation form in case of experimental theme.
    if ($this->willInstallExperimentalTheme($theme)) {
      return $this->formBuilder()->getForm(ThemeExperimentalConfirmForm::class, $theme);
@@ -156,9 +139,6 @@ public function install(Request $request) {
    return $this->redirect('system.themes_page');
  }

    throw new AccessDeniedHttpException();
  }

  /**
   * Checks if the given theme requires the installation of experimental themes.
   *
@@ -185,21 +165,16 @@ protected function willInstallExperimentalTheme($theme) {
  /**
   * Set the default theme.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   A request object containing a theme name.
   * @param string $theme
   *   The theme name.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse|array
   *   Redirects back to the appearance admin page or the confirmation form
   *   if an experimental theme will be installed.
   *
   * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
   *   Throws access denied when no theme is set in the request.
   */
  public function setDefaultTheme(Request $request) {
  public function setDefaultTheme(#[MapQueryParameter] string $theme) {
    $config = $this->configFactory->getEditable('system.theme');
    $theme = $request->query->get('theme');

    if (isset($theme)) {
    // Get current list of themes.
    $themes = $this->themeHandler->listInfo();
    // Display confirmation form if an experimental theme is being installed.
@@ -235,9 +210,6 @@ public function setDefaultTheme(Request $request) {
    }

    return $this->redirect('system.themes_page');

    }
    throw new AccessDeniedHttpException();
  }

}