You are here

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'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses PathAliasPathFieldUnserializer
path_alias.path.field.cdf.unserializer in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\PathAliasPathFieldUnserializer

File

src/EventSubscriber/UnserializeContentField/PathAliasPathFieldUnserializer.php, line 13

Namespace

Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField
View 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

Namesort descending Modifiers Type Description Overrides
PathAliasPathFieldUnserializer::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
PathAliasPathFieldUnserializer::onUnserializeContentField public function Handling for the PathAlias entity's 'path' field.