protected function RevisionHandler::updateParentRevision in Feeds Paragraphs 8
Updates the parent target's revision id.
Parameters
Paragraph $paragraph:
1 call to RevisionHandler::updateParentRevision()
- RevisionHandler::createRevision in src/
RevisionHandler.php - Creates a revision.
File
- src/
RevisionHandler.php, line 107
Class
Namespace
Drupal\feeds_para_mapperCode
protected function updateParentRevision(Paragraph $paragraph) {
$host_field = $paragraph
->get('parent_field_name')
->getValue()[0]['value'];
$revision_id = $paragraph
->updateLoadedRevisionId()
->getRevisionId();
$parent = $paragraph
->getParentEntity();
$values = $parent
->get($host_field)
->getValue();
$message = $this
->t("Failed to update host entity");
foreach ($values as $index => $value) {
if (isset($value['target_id']) && $value['target_id'] === $paragraph
->id()) {
$value['target_revision_id'] = $revision_id;
try {
$parent
->get($host_field)
->set($index, $value);
} catch (MissingDataException $e) {
$this->messenger
->addError($message);
$this->messenger
->addError($e);
}
}
}
try {
$parent
->save();
} catch (EntityStorageException $e) {
$this->messenger
->addError($message);
$this->messenger
->addError($e);
}
}