original_string: public function restore_instance_data_from_backup(\restore_task $task, array $data) {
          $courseid = $task->get_courseid();
          $context = $this->get_instance_context($courseid);
          $editablefields = $this->get_editable_fields($courseid);
          $records = api::get_instance_fields_data($editablefields, $courseid);
          $target = $task->get_target();
          $override = ($target != \backup::TARGET_CURRENT_ADDING && $target != \backup::TARGET_EXISTING_ADDING);
  
          foreach ($records as $d) {
              $field = $d->get_field();
              if ($field->get('shortname') === $data['shortname'] && $field->get('type') === $data['type']) {
                  if (!$d->get('id') || $override) {
                      $d->set($d->datafield(), $data['value']);
                      $d->set('value', $data['value']);
                      $d->set('valueformat', $data['valueformat']);
                      $d->set('contextid', $context->id);
                      $d->save();
                  }
                  return;
              }
          }
      }
code: public function restore_instance_data_from_backup(\restore_task $task, array $data) {
          $courseid = $task->get_courseid();
          $context = $this->get_instance_context($courseid);
          $editablefields = $this->get_editable_fields($courseid);
          $records = api::get_instance_fields_data($editablefields, $courseid);
          $target = $task->get_target();
          $override = ($target != \backup::TARGET_CURRENT_ADDING && $target != \backup::TARGET_EXISTING_ADDING);
  
          foreach ($records as $d) {
              $field = $d->get_field();
              if ($field->get('shortname') === $data['shortname'] && $field->get('type') === $data['type']) {
                  if (!$d->get('id') || $override) {
                      $d->set($d->datafield(), $data['value']);
                      $d->set('value', $data['value']);
                      $d->set('valueformat', $data['valueformat']);
                      $d->set('contextid', $context->id);
                      $d->save();
                  }
                  return;
              }
          }
      }
code_tokens: public function restore_instance_data_from_backup ( \ restore_task $ task , array $ data ) { $ courseid = $ task -> get_courseid ( ) ; $ context = $ this -> get_instance_context ( $ courseid ) ; $ editablefields = $ this -> get_editable_fields ( $ courseid ) ; $ records = api :: get_instance_fields_data ( $ editablefields , $ courseid ) ; $ target = $ task -> get_target ( ) ; $ override = ( $ target != \ backup :: TARGET_CURRENT_ADDING && $ target != \ backup :: TARGET_EXISTING_ADDING ) ; foreach ( $ records as $ d ) { $ field = $ d -> get_field ( ) ; if ( $ field -> get ( 'shortname' ) === $ data [ 'shortname' ] && $ field -> get ( 'type' ) === $ data [ 'type' ] ) { if ( ! $ d -> get ( 'id' ) || $ override ) { $ d -> set ( $ d -> datafield ( ) , $ data [ 'value' ] ) ; $ d -> set ( 'value' , $ data [ 'value' ] ) ; $ d -> set ( 'valueformat' , $ data [ 'valueformat' ] ) ; $ d -> set ( 'contextid' , $ context -> id ) ; $ d -> save ( ) ; } return ; } } }
docstring: Creates or updates custom field data.
  
  @param \restore_task $task
  @param array $data
docstring_tokens: Creates or updates custom field data .