public function PathAliasPathFieldUnserializer::onUnserializeContentField in Acquia Content Hub 8.2
Handling for the PathAlias entity's 'path' field.
Parameters
\Drupal\acquia_contenthub\Event\UnserializeCdfEntityFieldEvent $event: The unserialize event.
Throws
\Drupal\Core\Entity\EntityMalformedException
File
- src/
EventSubscriber/ UnserializeContentField/ PathAliasPathFieldUnserializer.php, line 32
Class
- PathAliasPathFieldUnserializer
- Generic field unserializer fallback subscriber.
Namespace
Drupal\acquia_contenthub\EventSubscriber\UnserializeContentFieldCode
public function onUnserializeContentField(UnserializeCdfEntityFieldEvent $event) {
if ($event
->getEntityType()
->id() === 'path_alias' && $event
->getFieldName() === 'path') {
$field = $event
->getField();
$values = [];
foreach ($field['value'] as $langcode => $value) {
if (empty($value['value']) || !Uuid::isValid($value['value'])) {
continue;
}
if ($event
->getStack()
->hasDependency($value['value'])) {
$wrapper = $event
->getStack()
->getDependency($value['value']);
$path = "/{$wrapper->getEntity()->toUrl()->getInternalPath()}";
$values[$langcode][$event
->getFieldName()] = $path;
}
}
$event
->setValue($values);
$event
->stopPropagation();
}
}