Answers.Body: <p>The function user_load is deprecated in D9.</p>
  <p><a href="https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/function/user_load/8.7.x" rel="nofollow noreferrer">https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/function/user_load/8.7.x</a></p>
  <p>Looks like we need a replacement stub function in the drupal module. For a quick hack, you could append this to /var/www/drupal/web/modules/contrib/civicrm/civicrm.module (or wherever it lives on your server).</p>
  <p>A better method might be to create a new D9 file of functions that gets loaded selectively only for D9.</p>
  <pre><code>/* for when user_load gets deprecated */
  
  if (!function_exists('user_load')) {
  
  function user_load($uid, $reset = FALSE) {
    if ($reset) {
      \Drupal::entityManager()
        -&gt;getStorage('user')
        -&gt;resetCache([
        $uid,
      ]);
    }
    return \Drupal\user\Entity\User::load($uid);
  }
  
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T20:38:32.960Z
Answers.Text: Put that into a PR and we'll all vote it up!
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T20:43:08.303Z
Answers.Text: @alan-dixon I have created a PR which basically does that but in a different way which should cover D8 and D9 https://github.com/civicrm/civicrm-core/pull/19517 but yours got be on the right direction
Answers.UserDisplayName: Seamus Lee
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T20:44:07.060Z
Answers.Text: you beat me by 30 seconds https://github.com/civicrm/civicrm-core/pull/19518
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T21:07:51.957Z
Answers.Text:  Thank you!
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-03T18:54:51.160Z
Answers.LastActivityDate: 2021-02-03T19:10:20.933Z
Answers.LastEditDate: 2021-02-03T19:10:20.933Z
Answers.UserDisplayName: Alan Dixon
Body: <p>Full error message:</p>
  <pre><code>Error: Call to undefined function user_load() in CRM_Utils_System_DrupalBase-&gt;getUserObject() (line 558 of /var/www/drupal/vendor/civicrm/civicrm-core/CRM/Utils/System/DrupalBase.php)
  </code></pre>
  <p>I get this when using an api3 call like this:</p>
  <pre><code>$result = civicrm_api3('User', 'get', [
    'sequential' =&gt; 1,
    'id' =&gt; 1,
  ]);
  </code></pre>
  
Tags: <api><drupal-8>
Title: Call to undefined function user_load() using Drupal 9 and api3?
ThreadText: # Call to undefined function user_load() using Drupal 9 and api3?
  
  (Asked by: username_0 on 2021-02-03)
  
  Full error message:
  Error: Call to undefined function user_load() in CRM_Utils_System_DrupalBase->getUserObject() (line 558 of /var/www/drupal/vendor/civicrm/civicrm-core/CRM/Utils/System/DrupalBase.php)
  
  I get this when using an api3 call like this:
  $result = civicrm_api3('User', 'get', [
    'sequential' => 1,
    'id' => 1,
  ]);
  
  **Tags:** api, drupal-8
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-02-03. Score: 3 | Accepted answer
  
  The function user_load is deprecated in D9.
  https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/function/user_load/8.7.x
  Looks like we need a replacement stub function in the drupal module. For a quick hack, you could append this to /var/www/drupal/web/modules/contrib/civicrm/civicrm.module (or wherever it lives on your server).
  A better method might be to create a new D9 file of functions that gets loaded selectively only for D9.
  /* for when user_load gets deprecated */
  
  if (!function_exists('user_load')) {
  
  function user_load($uid, $reset = FALSE) {
    if ($reset) {
      \Drupal::entityManager()
        ->getStorage('user')
        ->resetCache([
        $uid,
      ]);
    }
    return \Drupal\user\Entity\User::load($uid);
  }
  
  }
  
  > **Comments:**
  > **username_1**: Put that into a PR and we'll all vote it up!  
  > **username_2**: @alan-dixon I have created a PR which basically does that but in a different way which should cover D8 and D9 https://github.com/civicrm/civicrm-core/pull/19517 but yours got be on the right direction  
  > **username_3**: you beat me by 30 seconds https://github.com/civicrm/civicrm-core/pull/19518  
  > **username_1**:  Thank you!  
  
  ---
  
  