Verified Commit 57bf4fed authored by godotislate's avatar godotislate
Browse files

task: #3581569 Remove user_cookie_save() and user_cookie_delete()

By: znerol
By: catch
parent a0f6fd6a
Loading
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\system\Controller;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ExtensionLifecycle;
@@ -16,6 +17,7 @@
use Drupal\Core\Url;
use Drupal\system\SystemManager;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Cookie;

/**
 * Returns responses for System routes.
@@ -81,6 +83,8 @@ class SystemController extends ControllerBase {
   *   The module extension list.
   * @param \Drupal\Core\Extension\ThemeExtensionList $theme_extension_list
   *   The theme extension list.
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   */
  public function __construct(
    SystemManager $systemManager,
@@ -90,6 +94,7 @@ public function __construct(
    MenuLinkTreeInterface $menu_link_tree,
    ModuleExtensionList $module_extension_list,
    ThemeExtensionList $theme_extension_list,
    readonly protected TimeInterface $time,
  ) {
    $this->systemManager = $systemManager;
    $this->themeAccess = $theme_access;
@@ -176,8 +181,14 @@ public function overview($link_id) {
   *   A redirect response to the front page.
   */
  public function compactPage($mode) {
    user_cookie_save(['admin_compact_mode' => ($mode == 'on')]);
    return $this->redirect('<front>');
    $response = $this->redirect('<front>');
    if ($mode === 'on') {
      $response->headers->setCookie(new Cookie('Drupal.visitor.admin_compact_mode', '1', $this->time->getRequestTime() + 31536000));
    }
    else {
      $response->headers->clearCookie('Drupal.visitor.admin_compact_mode');
    }
    return $response;
  }

  /**
+12 −0
Original line number Diff line number Diff line
@@ -645,8 +645,14 @@ function user_form_process_password_confirm($element) {
 *
 * @param array $values
 *   An array of key/value pairs to be saved into a cookie.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3581570
 */
function user_cookie_save(array $values): void {
  @trigger_error(__METHOD__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3581570', E_USER_DEPRECATED);
  $request_time = \Drupal::time()->getRequestTime();
  foreach ($values as $field => $value) {
    // Set cookie for 365 days.
@@ -659,8 +665,14 @@ function user_cookie_save(array $values): void {
 *
 * @param string $cookie_name
 *   A cookie name such as 'homepage'.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3581570
 */
function user_cookie_delete($cookie_name): void {
  @trigger_error(__METHOD__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3581570', E_USER_DEPRECATED);
  setrawcookie('Drupal.visitor.' . $cookie_name, '', \Drupal::time()->getRequestTime() - 3600, '/');
}