dev/core#4756 check Drupal container available to check ip address
authorBW <ufundo@gmail.com>
Tue, 7 Nov 2023 15:17:02 +0000 (15:17 +0000)
committerBW <ufundo@gmail.com>
Tue, 7 Nov 2023 15:22:43 +0000 (15:22 +0000)
CRM/Utils/System/Drupal8.php

index 2ddb21bb5009b5b457d0a629739cf0cdc292c032..73cd9a270a121021be706ff2988dfa2cee34e081 100644 (file)
@@ -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();
   }
 
   /**