When watch for content is selected ParagraphsReport::getParasFromNid(): Argument #2 ($current) must be of type array, null given

Created on 20 August 2023, over 1 year ago
Updated 20 September 2024, 3 months ago

Problem/Motivation

When you have the "Watch for content" options selected, when saving a node, the following error is displayed.

TypeError: Drupal\paragraphs_report\ParagraphsReport::getParasFromNid(): Argument #2 ($current) must be of type array, null given, called in /app/web/modules/contrib/paragraphs_report/src/ParagraphsReport.php on line 478 in Drupal\paragraphs_report\ParagraphsReport->getParasFromNid() (line 327 of modules/contrib/paragraphs_report/src/ParagraphsReport.php).
Drupal\paragraphs_report\ParagraphsReport->insertParagraphs(Object) (Line: 33)
paragraphs_report_node_insert(Object)
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'paragraphs_report') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('node_insert', Object) (Line: 416)
Drupal\Core\Extension\ModuleHandler->invokeAll('node_insert', Array) (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object) (Line: 903)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object) (Line: 564)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, ) (Line: 784)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, ) (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 270)
Drupal\node\NodeForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 595)
Drupal\Core\Form\FormBuilder->processForm('node_article_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 681)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

drush si
drush en paragraphs_report -y
Log in as administrator
Navigate to /admin/reports/paragraphs-report/settings
Select Articles content type
Select "Watch for content changes and update report data"
Save configuration
Create a paragrah type called "Text" with one Long Formatted Text field
Add a field to the article content type called field_paragraphs allowing the paragraph type
Create a new article with the required title Test and one paragraph.

This seems to only happen when You have never Clicked "Update Report Data" before.

Proposed resolution

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States generalredneck

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @generalredneck
  • 🇮🇳India ayush.pandey

    The issue is reproducible with module version 2.x-dev on Drupal 10.1. The patch fixes the issue.

  • First commit to issue fork.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India abhishek_virasat

    @generalredneck, I have fixed this issue. please kindly review the MR

  • Assigned to generalredneck
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States generalredneck

    Hey, I appreciate both of yall taking a look at this. While identified areas where this would be a problem. I think the problem is bigger.

    Specifically aisforaaron is storing the report state in the configuration entity. that does mean that any time you do a configuration export after content is updated (and you don't ignore this configuration entity) that it will be updated...

    Example... after I run the report manually I get:

    _core:
      default_config_hash: WDVVbTde1eXP94qMDbx4NqQy4uOAEHLdyGsAcQBcF4o
    content_types:
      article: article
      page: 0
    hide_paras:
      text: 0
    import_rows_per_batch: '10'
    watch_content: 0
    report: '{"text":{"top":["1","2","3","4"]}}'
    

    Prior to doing so, I get

    _core:
      default_config_hash: WDVVbTde1eXP94qMDbx4NqQy4uOAEHLdyGsAcQBcF4o
    content_types:
      article: article
      page: 0
    hide_paras:
      text: 0
    import_rows_per_batch: '10'
    watch_content: 0
    

    I propose that we use the State API to store the report state instead of the Configuration Entity... and then we use abstracted retrieval of the state so that we can handle this error for all 3 places in one area. It's currently being handled inf ParagraphsReport::fetchJson(), but just not being used everywhere.

  • Status changed to Fixed 4 months ago
  • 🇺🇸United States generalredneck

    I pushed up the fix from ayush.pandey's patch because MR!12 did some reverts against some of the code changed in 2.x. Plus the patch works more completely.

    Pushing the changes of MR!16 to 🐛 Why are entities saved in config ? Active

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024