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

  1. Diff v8.x-1.0-cr1

Proposed Resolution

  • check if the $bundle has a method called bundle.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drup16 created an issue. See original summary.

drup16’s picture

Status: Active » Needs review
FileSize
683 bytes
drup16’s picture

Issue summary: View changes
drup16’s picture

After applying patch, tested the following test cases.

  1. Create a new page and publish, edit and create a new draft, view revisions, delete the recently created draft. (passed)
  2. Create a new draft for an existing page, click revisions tab, delete any revision, confirm the deletion (passed)
  3. Create a new page and save as a draft, create multiple revisions (5), delete a revision (e.g. 4th draft revision), confirm delete action (passed)
Ruslan Piskarov’s picture

Hello @drup16.
Thank you for the solution.
However, I am proposing a new patch and, in my opinion, this it more elegant.

drup16’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #6 works for me.

Diane Bryan’s picture

So, does this version of the D8 module appear to be working?

drup16’s picture

@Diane,

The module is working for us, but not under the scenarios described in this `Bug Report`

agentrickard’s picture

This module is seeking new maintainers. Please open an issue if you're able to maintain it.

alison’s picture

Patch 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 :)

nitvirus’s picture

Thanks for the RTBC.. let me just test this on my end and would commit the patch.

nitvirus’s picture

Tested 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.

  • nitvirus committed 81d5816 on 8.x-1.x
    Issue #2972780 by drup16,Ruslan Piskarov,agentrickard,alisonjo315,Diane...
nitvirus’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the efforts here,

I have pushed the code, moving the issue to FIXED.

nitvirus’s picture

Status: Fixed » Closed (fixed)