Views error when a row representing an entity does not have an associated scheduled transition

Created on 4 November 2022, about 2 years ago
Updated 20 June 2024, 5 months ago

Problem/Motivation

I have a view for moderate content which use fields from the Workflow module. I wanted to use the view fields provided by the Scheduled transitions module with my Moderated Content view to add new field to show if the content is scheduled for transition to a "New State" on the specified date "Transition on". However, it seems the "Transition on" is the only field that I can use as all other fields will fail to render and cause the view to break with this error:

Error: Call to a member function getEntity() on null in Drupal\scheduled_transitions\Plugin\views\field\ScheduledTransitionFromStateViewsField->render() (line 63 of modules/contrib/scheduled_transitions/src/Plugin/views/field/ScheduledTransitionFromStateViewsField.php).

Stack trace error:

Drupal\scheduled_transitions\Plugin\views\field\ScheduledTransitionFromStateViewsField->render() (Line: 1158)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender() (Line: 238)
template_preprocess_views_view_field()
call_user_func_array() (Line: 287)
Drupal\Core\Theme\ThemeManager->render() (Line: 422)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 1747)
Drupal\views\Plugin\views\field\FieldPluginBase->theme() (Line: 779)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 772)
Drupal\Core\Render\Renderer->doCallback() (Line: 363)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 718)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields() (Line: 584)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping() (Line: 475)
Drupal\views\Plugin\views\style\StylePluginBase->render() (Line: 2170)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1536)
Drupal\views\ViewExecutable->render() (Line: 199)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1633)
Drupal\views\ViewExecutable->executeDisplay() (Line: 81)
Drupal\views\Element\View::preRenderViewElement()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 772)
Drupal\Core\Render\Renderer->doCallback() (Line: 363)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 164)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 270)
Drupal\shield\ShieldMiddleware->bypass() (Line: 137)
Drupal\shield\ShieldMiddleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

  1. Go to the Structure → Views and edit the Content view.
  2. Expand the Advanced section and add relationship to the Scheduled transitions view "Reverse reference to Entity base field on scheduled transition".
  3. Add new field to the view. Filter by the Scheduled transitions category and select "Previous State", then Apply and save the changes.
  4. Go to Content.
🐛 Bug report
Status

Needs work

Version

2.4

Component

Code

Created by

🇺🇸United States alfattal Minnesota

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I think that the issue happens on rows in the view results for which there are no scheduled transitions. The value for the scheduled transition fields (new state, previous state and revision link) are empty, and the errors happen when Drupal, trying to render these fields, attempts to execute methods on these null values.

    I've added a simple check for null values. It works for me.

    I noticed that the code in ScheduledTransitionFromStateViewsField.php is quite different from ScheduledTransitionToStateViewsField.php. I don't understand the reason for this. Perhaps the module's maintainer will know.

  • Status changed to RTBC almost 2 years ago
  • 🇺🇸United States alfattal Minnesota

    Patch on #4 worked perfectly. Thank you @esomething!

  • First commit to issue fork.
  • 🇮🇳India urvashi_vora Madhya Pradesh, India

    Patch on #4 worked and saved a lot of struggle. Thank you @esomething, appreciate the work.

    Committing the changes to help the maintainers.

  • @urvashi_vora opened merge request.
  • Status changed to Needs work over 1 year ago
  • 🇦🇺Australia dpi Perth, Australia

    The suggested changes look ok.

    The diff's are quite noisy, can we change these to early exits instead of another layer of nesting.

    Please do not use `empty()`. Use appropriate type checking via instanceof or similar.

    Code supplied does not meet coding standards.

    We should have at least one test. The project has Views tests already, this should make it easier to implement.

  • 🇦🇺Australia dpi Perth, Australia
  • Status changed to Active 9 months ago
  • 🇺🇸United States alfattal Minnesota

    The patch in #4 failed to apply when upgrading to version 2.4.1 resulting in the same error message in the description. Changing the status to Active again.

  • Status changed to Needs work 9 months ago
  • 🇺🇸United States SocialNicheGuru

    Since there is a patch, it should be "Needs work"

  • 🇺🇸United States alfattal Minnesota

    @dpi Any chance to look at this issue? It's preventing me from upgrading to newer versions (I'm stuck with version 2.3.0). Thank you!

  • 🇦🇺Australia dpi Perth, Australia

    @13.

    I looked at it over a year ago, there has been no further progress. The issue remains NW.

  • Status changed to Needs review 7 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 7 months ago
    62 pass
  • 🇺🇸United States SocialNicheGuru

    I rerolled.
    If $scheduled_transition then return ''

  • Status changed to RTBC 7 months ago
  • 🇺🇸United States alfattal Minnesota

    Patch in #15 applied successfully on the 2.4 branch. Thank you, @SocialNicheGuru!

  • Status changed to Needs work 7 months ago
  • 🇦🇺Australia dpi Perth, Australia

    This issue is not ready as it still needs tests.

    We need to use MR's, in order to validate tests and code adheres to linting and static analysis. Especially as #9 described coding standard issues.

  • 🇦🇺Australia dpi Perth, Australia

    Rewording according to #4

Production build 0.71.5 2024