I have created new Display mode for the User Profile and it is rendered by "Views" blocks on the Articles page. Some content doesn't map with the User reference. In that scenario, I am getting undefined error.

Notice: Undefined property: Drupal\views\ViewExecutable::$result in Drupal\views\Plugin\views\query\Sql->getAllEntities() (line 1703 of core/modules/views/src/Plugin/views/query/Sql.php).

Drupal\views\Plugin\views\query\Sql->getAllEntities() (Line: 1676)
Drupal\views\Plugin\views\query\Sql->getCacheTags() (Line: 250)
Drupal\views\Plugin\views\cache\CachePluginBase->getCacheTags() (Line: 1566)
Drupal\views\ViewExecutable->getCacheTags() (Line: 2208)
Drupal\views\Plugin\views\display\DisplayPluginBase->applyDisplayCacheabilityMetadata(Array) (Line: 2183)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1533)
Drupal\views\ViewExecutable->render() (Line: 204)
Drupal\axelerant_blocks\Plugin\Block\UserProfileBlock->renderView('user_profile_name_designation_sbio_pic', Array, Array) (Line: 100)
Drupal\axelerant_blocks\Plugin\Block\UserProfileBlock->build() (Line: 171)
Drupal\block\BlockViewBuilder::preRender(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 501)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 222)
__TwigTemplate_25d39c79d9ad7d3603a431a0b745d7a82e5cf4be62efefde51ef3788a8cdc63c->doDisplay(Array, Array) (Line: 455)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template->display(Array) (Line: 60)
__TwigTemplate_e25beabb432e561ec32aa724c2a83865711a068f88c4ee4b61cee245839edb17->doDisplay(Array, Array) (Line: 455)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 422)
Twig\Template->display(Array) (Line: 434)
Twig\Template->render(Array) (Line: 64)
twig_render_template('themes/custom/axe/templates/content/node--content.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel-
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arulan_pari created an issue. See original summary.

arulan_pari’s picture

Please, Review my patch and I have tested in my local and its working fine.

arulan_pari’s picture

arulan_pari’s picture

Status: Active » Needs review
mayurjadhav’s picture

Status: Needs review » Needs work

Patch looks good for me, But Needs to add $row->_relationship_entities inside if condition.

rajandro’s picture

Assigned: Unassigned » rajandro

working on it.

rajandro’s picture

Addressed #5, now it should not display any notice for both the scenarios, please review.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This will need a test case to show the issue.

Did not test for the problem.

danflanagan8’s picture

I strongly think this should be closed. The ViewExecutable::$result property is clearly typehinted as an array of ResultRows and is initiated as an empty array:

  /**
   * Where the results of a query will go.
   *
   * The array must use a numeric index starting at 0.
   *
   * @var \Drupal\views\ResultRow[]
   */
  public $result = [];

I ran into a project that's using this patch because it has some ill-advised custom code that calls unset($view->result) in a pre_render hook. In my case, the bug is not in core; the bug is that I have custom code that is unsetting a property that is clearly declared as an array and should never be null. That's "illegal" and should be expected to have ugly side-effects.

I highly suspect that any codebase that requires this patch is similarly doing something it shouldn't be doing.

At the very least, this needs steps to reproduce that demonstrate there's some way to trigger this error without first doing something "illegal". I'm adding that tag.

But probably this should be closed as "won't fix".

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.