Problem/Motivation
Error: Call to a member function getEntityTypeId() on null in Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->entityCacheTagsFromRoute() (line 84 of modules/contrib/notification_message/src/Cache/Context/RouteEntityUuidCacheContext.php).
Drupal\notification_message\Cache\Context\RouteEntityUuidCacheContext->getContext(NULL) (Line: 123)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 317)
Drupal\Core\Render\RenderCache->createCacheID(Array) (Line: 66)
Drupal\Core\Render\RenderCache->get(Array) (Line: 109)
Drupal\Core\Render\PlaceholderingRenderCache->get(Array) (Line: 273)Steps to reproduce
Essentially the current function assumes that a contextual filter is going to be an ID, and a proper entity slug. The way to reproduce this is to really configure any other type of contextual filter. For our particular configuration:
- Create a new view with a page display and a path of anything/%taxonomy_term
- Create a new contextual filter which is the Term Name. This works normally with the taxonomy term validator.
Proposed resolution
There's not any super straightforward way to solve this. If you don't use an entity slug, and you just use '%', then it will fail on getStorage('arg_0').
If you setup the contextual filter to be a taxonomy term name, then the call to getStorage('taxonomy_term')->load('name of taxonomy term') will fail.
The best we can do is first do a hasDefinition() to see if the storage actually exists and if it's an actual entity type. Then attempt to load the entity and just continue if it fails.
Remaining tasks
Review and test included patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3397028--notification-message--undefined-function-getentitytypeid.patch | 2.68 KB | heikkiy |
| #4 | 3397028.patch | 1.8 KB | asherry |
Issue fork notification_message-3397028
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
asherry commentedComment #3
asherry commentedComment #4
asherry commentedRan into another error if the $arg variable turns out to be a proper EntityInterface object. I put in another check to see if it's a proper entity, just add it to the array, but, also check if it's an int/str to make sure it's safe to pass to entity load.
Still not sure about this solution as a whole, but, it's fixing errors for us at the moment.
Comment #5
heikkiy commentedI found this issue when installing Notification message to our side crashed a view with contextual filters in the URL.
The error in our case was this
The patch in this issue fixed the problem. I would be willing to mark this RTBC and mark it Major or even Critical because it causes a crash. I will see if I can come up with another suggestion how to fix this.
Comment #6
heikkiy commentedI tried to improve the code a bit and made some small improvements. Here is an attached patch with following changes.
1. Added a check for $route_object being null to avoid potential errors.
2. Used instanceof instead of is_a for checking if $arg is an instance of EntityInterface.
3. Some small style changes.
Tested that the issue is still resolved.
Comment #8
heikkiy commentedI opened a MR for this for easier review and commenting.
Comment #9
grgcrlsn321 commentedI'm marking this RTCB. It should be merged in because it breaks views easily using contextual filters. The patch solves the issue for handling the argument and adds validation for only passing entity types.
Comment #10
droath commentedCan someone confirm whether this issue still persists in the 2.x branch? I believe it has been addressed with the following patch: https://www.drupal.org/project/notification_message/issues/3590192.
Comment #11
droath commented