You are here

class ListNormalizer in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/serialization/src/Normalizer/ListNormalizer.php \Drupal\serialization\Normalizer\ListNormalizer

Converts list objects to arrays.

Ordinarily, this would be handled automatically by Serializer, but since there is a TypedDataNormalizer and the Field class extends TypedData, any Field will be handled by that Normalizer instead of being traversed. This class ensures that TypedData classes that also implement ListInterface are traversed instead of simply returning getValue().

Hierarchy

Expanded class hierarchy of ListNormalizer

1 file declares its use of ListNormalizer
ListNormalizerTest.php in core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php
Contains \Drupal\Tests\serialization\Unit\Normalizer\ListNormalizerTest.
1 string reference to 'ListNormalizer'
serialization.services.yml in core/modules/serialization/serialization.services.yml
core/modules/serialization/serialization.services.yml
1 service uses ListNormalizer
serializer.normalizer.list in core/modules/serialization/serialization.services.yml
Drupal\serialization\Normalizer\ListNormalizer

File

core/modules/serialization/src/Normalizer/ListNormalizer.php, line 19
Contains \Drupal\serialization\Normalizer\ListNormalizer.

Namespace

Drupal\serialization\Normalizer
View source
class ListNormalizer extends NormalizerBase {

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var string
   */
  protected $supportedInterfaceOrClass = 'Drupal\\Core\\TypedData\\ListInterface';

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = array()) {
    $attributes = array();
    foreach ($object as $fieldItem) {
      $attributes[] = $this->serializer
        ->normalize($fieldItem, $format);
    }
    return $attributes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ListNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass
ListNormalizer::normalize public function Normalizes an object into a set of arrays/scalars. Overrides NormalizerInterface::normalize
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer.
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerInterface::supportsNormalization 1
SerializerAwareNormalizer::$serializer protected property
SerializerAwareNormalizer::setSerializer public function Sets the owning Serializer object. Overrides SerializerAwareInterface::setSerializer