- Issue created by @andybroomfield
- Merge request !3Fix WSOD error when viewing entity with date_occurance field → (Merged) created by andybroomfield
- Status changed to Needs review
7 months ago 12:00pm 22 July 2024 - 🇬🇧United Kingdom andybroomfield
We're not setting this to anything, it's just a NULL value if it's not computed becuase we're viewing the entity page. it's outside of a search api view. But we get the WSOD even though we don't have the computed field in our manage display. It throws the error regardless.
- 🇬🇧United Kingdom joachim
It sounds like the computed field is not correctly reporting that it's empty?
- Status changed to Postponed: needs info
7 months ago 8:51pm 22 July 2024 - 🇬🇧United Kingdom joachim
Sorry, I misread the error message.
> Call to a member function isEmpty() on null
That means that the $entity->get(FIELD) failed.
Why is the field missing? Can you debug?
- 🇬🇧United Kingdom andybroomfield
Looking at $entity->get($field) on the node page gives me
Drupal\computed_field\Field\ComputedFieldClass {#2574 ▼ #definition: Drupal\computed_field\Field \ ComputedFieldDefinition {#2572 ▶} #name: "localgov_event_date_occurrence" #parent: Drupal\Core\Entity\Plugin\DataType \ EntityAdapter {#2423 ▶} #_serviceIds: [] #_entityStorages: [] #stringTranslation: null #typedDataManager: Drupal\Core\TypedData \ TypedDataManager {#594 ▶} #list: [] #langcode: "en" #valueComputed: true }
On the Search API page I get
Drupal\computed_field\Field\ComputedFieldClass {#9711 ▼ #definition: Drupal\computed_field\Field \ ComputedFieldDefinition {#9742 ▶} #name: "localgov_event_date_occurrence" #parent: Drupal\Core\Entity\Plugin\DataType \ EntityAdapter {#9788 ▶} #_serviceIds: [] #_entityStorages: [] #stringTranslation: null #typedDataManager: Drupal\Core\TypedData \ TypedDataManager {#1240 ▶} #list: array:1 [▼ 0 => Drupal\datetime_range\Plugin\Field\FieldType \ DateRangeItem {#9688 ▼ #definition: Drupal\Core\Field\TypedData \ FieldItemDataDefinition {#9741 ▶} #name: 0 #parent: Drupal\computed_field\Field \ ComputedFieldClass {#9711} #_serviceIds: [] #_entityStorages: [] #stringTranslation: null #typedDataManager: Drupal\Core\TypedData \ TypedDataManager {#1240 ▶} #values: array:3 [ …3] #properties: array:2 [ …2] } ] #langcode: "en" #valueComputed: true }
I traced the NULL value to docroot/core/lib/Drupal/Core/TypedData/ComputedItemListTrait.php which the get method returns NULL if there is no value in the index.
public function get($index) { if (!is_numeric($index)) { throw new \InvalidArgumentException('Unable to get a value with a non-numeric delta in a list.'); } // Unlike the base implementation of // \Drupal\Core\TypedData\ListInterface::get(), we do not add an empty item // automatically because computed item lists need to behave like // non-computed ones. For example, calling isEmpty() on a computed item list // should return TRUE when the values were computed and the item list is // truly empty. // @see \Drupal\Core\TypedData\Plugin\DataType\ItemList::get(). $this->ensureComputedValue(); return $this->list[$index] ?? NULL; }
I think it returns NULL as the ComputeValue of src/Plugin/ComputedField/DateOccurrence.php will return an empty array. I can change this to ['now'] and the entity pages get a dateTime of the current date.
- 🇬🇧United Kingdom joachim
Oh. There are two get() calls and they're not the same. That's why I'm confused!
$date_occurrence_field = $entity->get($field_name)->get(0);
$entity->get(FIELDNAME) gets us the FieldItemListInterface for the field. That one's fine, right?
FieldItemListInterface->get(0) is one of those weird magic ones maybe?
Maybe we should be calling isEmpty() on the FieldItemListInterface instead? Can you try that?
- Status changed to Needs review
7 months ago 8:53am 30 July 2024 - 🇬🇧United Kingdom andybroomfield
Bumping back to needs review for the updated MR.
-
joachim →
committed 3d97269d on 1.0.x authored by
andybroomfield →
Issue #3463077 by andybroomfield: Call to a member function isEmpty() on...
-
joachim →
committed 3d97269d on 1.0.x authored by
andybroomfield →
- 🇬🇧United Kingdom joachim
Sorry it's taken me this long to look at this.
Reproduced the bug, confirmed the fix.
Will make a new release.
Thanks!
Automatically closed - issue fixed for 2 weeks with no activity.