You are here

protected function ImageItemNormalizer::constructValue in Content Synchronization 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Normalizer/ImageItemNormalizer.php \Drupal\content_sync\Normalizer\ImageItemNormalizer::constructValue()

Build the field item value using the incoming data.

Most normalizers that extend this class can simply use this method to construct the denormalized value without having to override denormalize() and reimplementing its validation logic or its call to set the field value.

It's recommended to not override this and instead provide a (de)normalizer at the DataType level.

Parameters

mixed $data: The incoming data for this field item.

array $context: The context passed into the Normalizer.

Return value

mixed The value to use in Entity::setValue().

Overrides EntityReferenceFieldItemNormalizer::constructValue

File

src/Normalizer/ImageItemNormalizer.php, line 21

Class

ImageItemNormalizer

Namespace

Drupal\content_sync\Normalizer

Code

protected function constructValue($data, $context) {
  $denormalized_data = parent::constructValue($data, $context);
  foreach ([
    'alt',
    'title',
  ] as $field) {
    if (!empty($data[$field])) {
      $denormalized_data[$field] = $data[$field];
    }
  }
  return $denormalized_data;
}