- Issue created by @jsutta
- Merge request !73Added $type parameter to recursive call of the buildRelationshipJson in src/GatsbyEntityLogger.php. β (Open) created by jsutta
On our site we have a paragraph type that has two paragraph fields. It looks similar to the following:
Granted, this is a LOT of nesting, I know.
The issue is that when you have a published version of a node, and then you make a change to one of these nested paragraphs, and click the Open Gatsby Preview button, the changes to the nested paragraphs aren't reflected in the preview.
Here are the relevant enabled modules:
Steps to reproduce:
When you click Open Gatsby Preview, the value of the Key image field will be the published version, not the updated version.
After a lot of digging, I found that the solution is simple.
In src/GatsbyEntityLogger.php
, the buildRelationshipJson
method recursively traverses all related entities to build a JSON object containing the data needed to build the preview.
The buildRelationshipJson
method has a parameter called $type
, which determines if the webhook it's working on is for a build or a preview. By default, it's set to build
.
In all other calls to the buildRelationshipJson
method, the $type
value is passed along with the other arguments. But, in the call where the method recursively calls itself, the $type
value is not passed, which means it defaults to build
. This means that in the following statement, the related entity is loaded via its uuid, which gets the current revision, rather than via its latest revision:
if ($type == 'preview' && !empty($related_data['meta']['target_revision_id'])) {
$related_entity = $this->entityTypeManager->getStorage($entity_ref_type)
->loadRevision($related_data['meta']['target_revision_id']);
}
else {
$related_entity = $this->entityRepository->loadEntityByUuid($entity_ref_type, $related_data['id']);
}
To resolve this, simply change
if (!empty($related_json['data']['relationships'])) {
$this->buildRelationshipJson($related_json['data']['relationships'], $entity_data, $included_types, $entity_ref_type, $entity_ref_bundle);
}
to
if (!empty($related_json['data']['relationships'])) {
$this->buildRelationshipJson($related_json['data']['relationships'], $entity_data, $included_types, $entity_ref_type, $entity_ref_bundle<strong>, $type</strong>);
}
Active
2.0
Code