You are here

protected function PathautoItemNormalizer::constructValue in Tome 8

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 FieldableEntityNormalizerTrait::constructValue

File

modules/tome_sync/src/Normalizer/PathautoItemNormalizer.php, line 34

Class

PathautoItemNormalizer
Normalizer for Pathauto.

Namespace

Drupal\tome_sync\Normalizer

Code

protected function constructValue($data, $context) {

  // If the pathauto property is set to 1 and there is no pattern for this
  // entity, the default URL alias is not respected.
  if (!isset($data['pathauto']) || $data['pathauto'] === PathautoState::CREATE) {
    $data['pathauto'] = $context['target_instance']
      ->get('pathauto')
      ->getValue();
  }
  return parent::constructValue($data, $context);
}