From 997d471eec83ab5e28f7714e547c3950ddaae945 Mon Sep 17 00:00:00 2001 From: BW Date: Tue, 7 Nov 2023 15:17:02 +0000 Subject: [PATCH] dev/core#4756 check Drupal container available to check ip address --- CRM/Utils/System/Drupal8.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 2ddb21bb50..73cd9a270a 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -944,7 +944,11 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { * @inheritdoc */ public function ipAddress():?string { - return class_exists('Drupal') ? \Drupal::request()->getClientIp() : ($_SERVER['REMOTE_ADDR'] ?? NULL); + // dev/core#4756 fallback if checking before CMS bootstrap + if (!class_exists('Drupal') || !\Drupal::hasContainer()) { + return ($_SERVER['REMOTE_ADDR'] ?? NULL); + } + return \Drupal::request()->getClientIp(); } /** -- 2.25.1