You are here

class FallbackFieldUnserializer in Acquia Content Hub 8.2

Generic field unserializer fallback subscriber.

Hierarchy

  • class \Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\FallbackFieldUnserializer implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of FallbackFieldUnserializer

1 string reference to 'FallbackFieldUnserializer'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses FallbackFieldUnserializer
fallback.field.cdf.unserializer in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField\FallbackFieldUnserializer

File

src/EventSubscriber/UnserializeContentField/FallbackFieldUnserializer.php, line 12

Namespace

Drupal\acquia_contenthub\EventSubscriber\UnserializeContentField
View source
class FallbackFieldUnserializer implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::UNSERIALIZE_CONTENT_ENTITY_FIELD] = [
      'onUnserializeContentField',
    ];
    return $events;
  }

  /**
   * Naive handling for fields that don't have special handling.
   *
   * @param \Drupal\acquia_contenthub\Event\UnserializeCdfEntityFieldEvent $event
   *   The unserialize event.
   */
  public function onUnserializeContentField(UnserializeCdfEntityFieldEvent $event) {
    $field = $event
      ->getField();
    $values = [];
    if (!empty($field['value'])) {
      foreach ($field['value'] as $langcode => $value) {
        $values[$langcode][$event
          ->getFieldName()] = $value;
      }
      $event
        ->setValue($values);
    }
    $event
      ->stopPropagation();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FallbackFieldUnserializer::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
FallbackFieldUnserializer::onUnserializeContentField public function Naive handling for fields that don't have special handling.