class PathAliasPathFieldUnserializer in Acquia Content Hub 8.2
Generic field unserializer fallback subscriber.
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\PathAliasPathFieldUnserializer implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of PathAliasPathFieldUnserializer
1 string reference to 'PathAliasPathFieldUnserializer'
1 service uses PathAliasPathFieldUnserializer
File
- src/
EventSubscriber/ UnserializeContentField/ PathAliasPathFieldUnserializer.php, line 13
Namespace
Drupal\acquia_contenthub\EventSubscriber\UnserializeContentFieldView source
class PathAliasPathFieldUnserializer implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::UNSERIALIZE_CONTENT_ENTITY_FIELD] = [
'onUnserializeContentField',
10,
];
return $events;
}
/**
* Handling for the PathAlias entity's 'path' field.
*
* @param \Drupal\acquia_contenthub\Event\UnserializeCdfEntityFieldEvent $event
* The unserialize event.
*
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
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();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PathAliasPathFieldUnserializer:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
PathAliasPathFieldUnserializer:: |
public | function | Handling for the PathAlias entity's 'path' field. |