示例#1
0
  /**
   * 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.
   *
   * @param $update
   * @param $entity_to_update
   */
  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);
          }
        }
      }
    }
  }