Drupal 10 Depreciated Function Fixes

Created on 16 January 2025, 6 months ago

Problem/Motivation

I was getting the following errors:

Deprecated function: Creation of dynamic property Drupal\ddos_security\EventSubscriber\AttackProtection::$currentUser is deprecated in Drupal\ddos_security\EventSubscriber\AttackProtection->__construct() (line 98 of modules/contrib/ddos_security/src/EventSubscriber/AttackProtection.php).

Drupal\ddos_security\EventSubscriber\AttackProtection->__construct() (Line: 261)
Drupal\Component\DependencyInjection\Container->createService() (Line: 179)
Drupal\Component\DependencyInjection\Container->get() (Line: 105)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 157)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Also this:

Deprecated function: Creation of dynamic property Drupal\ddos_security\EventSubscriber\AttackProtection::$sessionManager is deprecated in Drupal\ddos_security\EventSubscriber\AttackProtection->__construct() (line 99 of modules/contrib/ddos_security/src/EventSubscriber/AttackProtection.php).

Drupal\ddos_security\EventSubscriber\AttackProtection->__construct() (Line: 261)
Drupal\Component\DependencyInjection\Container->createService() (Line: 179)
Drupal\Component\DependencyInjection\Container->get() (Line: 105)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 157)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Install the module in Drupal 10, get error notices.

Proposed resolution

Apply the patch file I've attached.
directly:
replace
protected $account;
with
protected AccountProxyInterface $currentUser;

add:
protected SessionManagerInterface $sessionManager;

in: public function __construct, replace this code inside the parentheses:
AccountProxyInterface $account,
with
AccountProxyInterface $current_user,

in the function, replace the following:
$this->currentUser = $account;
with
$this->currentUser = $current_user;

This appears to make all the errors go away after clearing cache.

๐Ÿ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States rex.barkdoll

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024