- Issue created by @stayr
- Status changed to Needs review
5 months ago 12:33pm 18 July 2024 Hi @stayr,
You received this error due to a type hint mismatch. The error occurs when the type of the argument being passed to the constructor does not match the expected type. I reviewed your code and identified that you need to add some lines to the 'services.yml' file.
Please refer to the attached patch for details.
Thanks!
After patch error
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
After patch error
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
- Status changed to Active
5 months ago 12:48pm 18 July 2024 After patch error
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
- Status changed to Needs review
5 months ago 12:48pm 18 July 2024 After patch error
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
After patch error
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
- Status changed to Active
5 months ago 12:51pm 18 July 2024 After patch error
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
- Assigned to stayr
Error after path
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
Error after path
Error: Call to a member function getAccount() on null in Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField->getContext() (line 60 of modules/contrib/user_ref_field_cache_context/src/CacheContext/UserReferenceField.php).
I'm not knowledgeable on patch creation. But here are the changes I made to fix this issue:
In the patch above, I had to remove the lines:
class: Drupal\user_ref_field_cache_context\CacheContext\UserReferenceField
- arguments: ['@current_user']In the file /src/CacheContext/UserReferenceField.php:
60c60
< $current_user_id = \Drupal::currentUser()->id();
---
> $current_user_id = $this->user->getAccount()->id();
62c62
< $user = $this->entityTypeManager->getStorage('user')->load($current_user_id);
---
> $user = $this->entityTypeManager()->getStorage('user')->load($current_user_id);- First commit to issue fork.
- 🇨🇦Canada mandclu
We shouldn't move away from using dependency injection. Please review MR!3 and let me know if this resolves the original error.