Prevent PHP warning when creating a node with Drupal 7.79 and it's new field storage optimization #233
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Drupal 7.79 (release notes) added a field storage optimization (change record) that can be enabled by setting a variable in the site's
settings.php
:With this enabled, creating nodes in Behat with the Drupal extension, for example:
... will lead to a PHP warning like this:
This was discovered on a project which has Behat setup to treat PHP notices/warnings as test failures, so it's actually breaking the test suite in this case.
After digging into this, it seems the problem is that the new field storage optimization is comparing
$node
to$node->original
, butDrupal\Driver\Cores\Drupal7::nodeCreate()
is doing$node->original = clone $node
before the fields are expanded by$this->expandEntityFields()
. That means that$node->original->body
contains a string, rather than an array in the proper format for a Drupal field, which leads to the PHP warning.One possible solution would be to move the
$node->original = clone $node
after the$this->expandEntityFields()
so that$node->original->body
is expanded. However, in normal operation, Drupal doesn't set$node->original
when creating a new node, only when updating an existing node. So, I don't this this actually needed at all, and this PR just removes it.This fixes the PHP warning in my testing.