protected function ContentEntityNormalizer::denormalizeMenuLinkParent in Replication 8
Same name and namespace in other branches
- 8.2 src/Normalizer/ContentEntityNormalizer.php \Drupal\replication\Normalizer\ContentEntityNormalizer::denormalizeMenuLinkParent()
Parameters
$data:
$context:
$langcode:
Return value
string
1 call to ContentEntityNormalizer::denormalizeMenuLinkParent()
- ContentEntityNormalizer::denormalizeTranslation in src/
Normalizer/ ContentEntityNormalizer.php
File
- src/
Normalizer/ ContentEntityNormalizer.php, line 580
Class
Namespace
Drupal\replication\NormalizerCode
protected function denormalizeMenuLinkParent($data, $context, $langcode) {
if (strpos($data, 'menu_link_content') === 0) {
list($type, $uuid, $id) = explode(':', $data);
if ($type === 'menu_link_content' && $uuid && is_numeric($id)) {
$storage = $this->entityManager
->getStorage('menu_link_content');
$parent = $storage
->loadByProperties([
'uuid' => $uuid,
]);
$parent = reset($parent);
if ($parent instanceof MenuLinkContentInterface && $parent
->id() && $parent
->id() != $id) {
return $type . ':' . $uuid . ':' . $parent
->id();
}
elseif (!$parent) {
// Create a new menu link as stub.
$parent = $storage
->create([
'uuid' => $uuid,
'link' => 'internal:/',
'langcode' => $langcode,
]);
// Set the target workspace if we have it in context.
if (isset($context['workspace']) && $context['workspace'] instanceof WorkspaceInterface) {
$parent->workspace->target_id = $context['workspace']
->id();
}
// Indicate that this revision is a stub.
$parent->_rev->is_stub = TRUE;
$parent
->save();
return $type . ':' . $uuid . ':' . $parent
->id();
}
}
}
return $data;
}