public function JobItemForm::resolveDiff

Submit handler to resolve the diff updating the Job Item source.

File

src/Form/JobItemForm.php, line 745

Class

JobItemForm
Form controller for the job item edit forms.

Namespace

Drupal\tmgmt\Form

Code

public function resolveDiff(array $form, FormStateInterface $form_state) {
  $item = $this->entity;
  $key = $form_state
    ->getTriggeringElement()['#data_item_key'];
  $array_key = \Drupal::service('tmgmt.data')
    ->ensureArrayKey($key);
  $first_key = reset($array_key);
  $source_data = $item
    ->getSourceData();
  $new_data = \Drupal::service('tmgmt.data')
    ->flatten($source_data)[$key];
  $item
    ->updateData($key, $new_data);
  if (isset($source_data[$first_key]['#label'])) {
    $item
      ->addMessage('The conflict in the data item source "@data_item" has been resolved.', [
      '@data_item' => $source_data[$first_key]['#label'],
    ]);
  }
  else {
    $item
      ->addMessage('The conflict in the data item source has been resolved.');
  }
  $item
    ->save();
  $form_state
    ->set('show_diff:' . $key, FALSE);
  $form_state
    ->setRebuild();
}