Quantcast
Viewing all articles
Browse latest Browse all 296340

FieldItemList::getEntity should handle ::getParent returning NULL.

Problem/Motivation

If you create a typed data object based on FieldDefinitionInterface and then validate that typed object, you may encounter:

Error: Call to a member function getValue() on null

Here is the stack trace when validating a typed data object for PathItem without an parent entity.

[Sun Apr 19 21:57:23 2020] Error: Call to a member function getValue() on null in /Users/john/code/drupal-core/core/lib/Drupal/Core/Field/FieldItemList.php on line 50 #0 /Users/john/code/drupal-core/core/lib/Drupal/Core/Field/FieldItemBase.php(61): Drupal\Core\Field\FieldItemList->getEntity()
#1 /Users/john/code/drupal-core/core/modules/path/src/Plugin/Validation/Constraint/PathAliasConstraintValidator.php(46): Drupal\Core\Field\FieldItemBase->getEntity()

FieldItemList::getEntity always assumes there is a parent set, but it shouldn't, as per TypedData::getParent() doxygen.

   * @return \Drupal\Core\TypedData\TraversableTypedDataInterface|null
   *   The parent data structure, either complex data or a list; or NULL if this
   *   is the root of the typed data tree.

Proposed resolution

Update doxygen that getEntity might return NULL, and ensure it does when getParent() do.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 296340

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>