Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motiviation
When attempting to delete a revision that is not published, the following error occurs. This happens for pages that are excluded and not exclude using Cache exclude. This is preventing us from deleting the revision.
The website encountered an unexpected error. Please try again later.
Error: Call to a member function bundle() on string in Drupal\cacheexclude\EventSubscriber\CacheexcludeSubscriber->disableCacheForPage() (line 49 of modules\contrib\cacheexclude\src\EventSubscriber\CacheexcludeSubscriber.php).
Drupal\cacheexclude\EventSubscriber\CacheexcludeSubscriber->disableCacheForPage(Object, 'kernel.request', Object)
call_user_func(Array, Object, 'kernel.request', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.request', Object) (Line: 127)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Line of code
// Check if current node type is one we want to exclude from the cache.
if ($bundle = \Drupal::routeMatch()->getParameter('node')) {
$bundle_type = $bundle->bundle();
}
Other modules enabled
Proposed Resolution
- check if the $bundle has a method called bundle.
Comment | File | Size | Author |
---|---|---|---|
#6 | php-fatal-error-2972780-6.patch | 1.4 KB | Ruslan Piskarov |
#3 | cacheexclude-2972780-3.patch | 683 bytes | drup16 |
Comments
Comment #2
drup16 CreditAttribution: drup16 commentedComment #3
drup16 CreditAttribution: drup16 commentedComment #4
drup16 CreditAttribution: drup16 commentedComment #5
drup16 CreditAttribution: drup16 commentedAfter applying patch, tested the following test cases.
Comment #6
Ruslan PiskarovHello @drup16.
Thank you for the solution.
However, I am proposing a new patch and, in my opinion, this it more elegant.
Comment #7
drup16 CreditAttribution: drup16 commentedPatch from #6 works for me.
Comment #8
Diane Bryan CreditAttribution: Diane Bryan commentedSo, does this version of the D8 module appear to be working?
Comment #9
drup16 CreditAttribution: drup16 commented@Diane,
The module is working for us, but not under the scenarios described in this `Bug Report`
Comment #10
agentrickardThis module is seeking new maintainers. Please open an issue if you're able to maintain it.
Comment #11
alisonPatch on #6 works great for us, too, for almost a month now 👍 Just wanted to +1 the RTBC, in case a new maintainer is checking out the issue queue :)
Comment #12
nitvirus CreditAttribution: nitvirus at Srijan | A Material+ Company commentedThanks for the RTBC.. let me just test this on my end and would commit the patch.
Comment #13
nitvirus CreditAttribution: nitvirus at Srijan | A Material+ Company commentedTested this.
Steps taken:
1. enabled cacheExclude module.
2. made new node with 2 revisions.
3. tried to delete the the older revision.
4. Got error when patch was not applied.
5. applied #6 patch, and tried deleting again.
6. the node revision was sucessfully deleted.
would be pushing this to dev branch for now and would be updating the stable branch after this.
Thanks for all the contribiutions.
Comment #15
nitvirus CreditAttribution: nitvirus at Srijan | A Material+ Company commentedThanks for the efforts here,
I have pushed the code, moving the issue to FIXED.
Comment #16
nitvirus CreditAttribution: nitvirus at Srijan | A Material+ Company commented