You are here

protected function BaseUpdateRunner::transferFieldValues in Scheduled Updates 8

Transfer field values from update to entity to be updated.

Because different fields may be on different bundles not all fields will be transferred to all entities.

Parameters

$update:

$entity_to_update:

1 call to BaseUpdateRunner::transferFieldValues()
BaseUpdateRunner::prepareEntityForUpdate in src/Plugin/BaseUpdateRunner.php
Prepare an entity to be updated.

File

src/Plugin/BaseUpdateRunner.php, line 342
Contains \Drupal\scheduled_updates\Plugin\BaseUpdateRunner.

Class

BaseUpdateRunner

Namespace

Drupal\scheduled_updates\Plugin

Code

protected function transferFieldValues(ScheduledUpdateInterface $update, ContentEntityInterface $entity_to_update) {
  $field_map = $this->scheduled_update_type
    ->getFieldMap();
  foreach ($field_map as $from_field => $to_field) {
    if ($to_field) {
      if ($entity_to_update
        ->hasField($to_field) && $update
        ->hasField($from_field)) {
        $new_value = $update
          ->get($from_field)
          ->getValue();

        // @todo if $new_value is empty. Check to see if the field is required on the target?
        //  If it is require don't update value because this cause a fatal at least on base fields.
        if (isset($new_value)) {
          $entity_to_update
            ->set($to_field, $new_value);
        }
      }
    }
  }
}