I have a personal flag setup for AUTHENTICATED USER. no problem for authenticated users, but I got the error below when anonymous when they go to the node page. please advise. ( I noticed the problem is only happened when I set the link type to "Count link", if I change to ajax link then the problem gone )
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\flag\TwigExtension\FlagCount::count() must implement interface Drupal\flag\FlagInterface, null given, called in /home/xx/public_html/web/sites/default/files/php/twig/62c74d7e62e5c_flag-count.html.twig_o3BzpAD5mRLvllwl8oGhKAnyG/A5Gd-5PDinRR3LxnxaP8i2DBUcSxPpAS6ewEtqQRXHs.php on line 67 in Drupal\flag\TwigExtension\FlagCount->count() (line 64 of modules/flag/src/TwigExtension/FlagCount.php).
Drupal\flag\TwigExtension\FlagCount->count(NULL, NULL) (Line: 67)
__TwigTemplate_9154b0721101147f4324558e3fceea7b24e25cd62199bb2f377a344aefa8b0d9->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('modules/flag/modules/flag_count/templates/flag-count.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('flag_count', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 157)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 158)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 172)
Drupal\Core\Render\Renderer->renderPlaceholder('', Array) (Line: 649)
Drupal\Core\Render\Renderer->replacePlaceholders(Array) (Line: 534)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 145)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 146)
Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 279)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders(Object) (Line: 71)
Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor->processAttachments(Object) (Line: 45)
Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.response') (Line: 191)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 179)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
nt.php).
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | flag-count_check-3294851-15.patch | 864 bytes | manishsaharan |
Issue fork flag-3294851
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
freelylw commentedComment #3
rik.scholtenI added two checks that make sure the params are set before you try to access them. This removes the white page errors for anonymous users.
Comment #4
jaydev bhatt commented@rik.scholten if you have generated this page can we move this to Needs Review?
Comment #5
rik.scholtenYou are correct, I forgot to change the status. Thanks!
Comment #6
berdirThat seems like a hack. the twig template should check if there is a flag, I'd assume this results in displaying empty [].
Comment #7
rik.scholtenHi Berdir, you are 100% correct. This patch checks the flag and flaggable in the twig template, if one of these is NULL the twig template will not render the count. I tested it and it seems to get the desired outcome.
Please let me know if this is better, thanks in advance!
Comment #8
rik.scholtenRemove one line of whitespace.
Comment #9
berdirMakes sense, but you need to reroll this against 8.x-4.x-dev because I made a conflicting change there for D10 compatibility.
Comment #10
rik.scholtenRerolled patch against 8.x-4.x-dev. Thanks!
Comment #11
B1 commentedD9.5
PHP 8.1.7
Flag 8.x-4.0-beta3
A flag count of 0 is shown to users.
Apply patch to twig template.
If flag is NULL the twig template successfully hides 0 count to users.
No known errors occur from patch and patch deemed successful in this particular use case.
Comment #12
rik.scholtenComment #13
tree2009 commentedRTBC+1
Comment #14
ivnishNeeds reroll to MR, needs tests how it works
Comment #15
manishsaharan commentedRerolled patch against 5.x branch
Comment #16
ivnish@manishsaharan needs reroll to MR. Also needs tests to show that the template is not broken after this patch
Comment #19
deaom commentedI think the tests currently present already cover this scenario, they are added in the main module, so setting status to Needs review if additional test are needed, please provide information on what needs to be tested.
Comment #21
ivnishMerged! thanks!