Error Encountered: Call to a member function getValue() on null in Drupal\Core\Field\FieldItemList->getEntity()

Created on 11 January 2023, almost 2 years ago
Updated 2 October 2023, about 1 year ago

Problem/Motivation

We are encountering the error stated in subject as we try to serialize an entity.

This issue is already tackled and discussed previously on https://www.drupal.org/project/office_hours/issues/1998266 Add "Exception day" feature Fixed .

As we had updated the said module to the latest release version 8.x-1.7, we are still encountering some issues as stated in https://www.drupal.org/project/office_hours/issues/1998266#comment-14483354 Add "Exception day" feature Fixed (comment #109). The solution proposed in https://www.drupal.org/project/office_hours/issues/1998266#comment-14483843 Add "Exception day" feature Fixed resolved the exception handling issues. However when applying the patch available, it is encountering an issue as the patch is directly referenced from the previous release version (8.x-1.6).

Proposed resolution

Create a patch similar to the patch attached in https://www.drupal.org/project/office_hours/issues/1998266#comment-14483843 Add "Exception day" feature Fixed , but need to be referenced on 8.x-1.7 release version.

🐛 Bug report
Status

Fixed

Version

1.7

Component

Code - widget

Created by

🇵🇭Philippines meralvingrita24 Cabuyao City, Laguna

Live updates comments and jobs are added and updated live.
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.

  • Status changed to Fixed almost 2 years ago
  • Status changed to Needs work almost 2 years ago
  • 🇳🇱Netherlands johnv

    Hmm, I can reproduce it using the WebformOfficeHours element.
    Test:
    - enable Webform + WebForm UI
    - create a Webform with an Office Hours element
    - create a submission
    - check the submission via admin/structure/webform/manage/TYPE/results/submissions

    • johnv committed a46aabd2 on 8.x-1.x
      Issue #3332500: Fix Error in WebformOfficehours: Call to a member...
  • 🇳🇱Netherlands johnv

    Above patch fixes the problem when displaying a Webform Submission with WebFormOfficeHours.
    It is rather big - working on other issues as well.

    Main change is this, adding a parent:

    -  protected function unserialize(array $office_hours, array $element) {
    +  protected function unserialize(array $office_hours, array $element, WebformSubmissionInterface $webform_submission) {
    -    /** @var \Drupal\Core\Field\FieldItemListInterface $items */
    -    $items = \Drupal::typedDataManager()
    -      ->create($this->getFieldDefinition($element));
    -
    ...
    +    /** @var \Drupal\Core\Field\FieldItemListInterface $items */
    +    $items = \Drupal::typedDataManager()
    +      ->create($this->getFieldDefinition(),
    +        $values,
    +        $element['#webform_key'],
    +        $webform_submission->getTypedData()
    +      );
    +    $items->filterEmptyItems();
         return $items;
       }
    
  • 🇳🇱Netherlands johnv

    @original posters,
    please share debug_backtrace(), so I can better check the root cause of your problem (or report back when the above change has successfully removed the error.)

  • Status changed to Postponed: needs info almost 2 years ago
  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024