public function JobResubmitForm::submitForm

File

src/Form/JobResubmitForm.php, line 35

Class

JobResubmitForm
Provides a form for deleting a node.

Namespace

Drupal\tmgmt\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $new_job = $this->entity
    ->cloneAsUnprocessed();
  $new_job->uid = $this
    ->currentUser()
    ->id();
  $new_job
    ->save();

  /** @var \Drupal\tmgmt\JobItemInterface $item */
  foreach ($this->entity
    ->getItems() as $item) {
    $item_to_resubmit = $item
      ->cloneAsActive();
    $new_job
      ->addExistingItem($item_to_resubmit);
  }
  $this->entity
    ->addMessage('Job has been duplicated as a new job <a href=":url">#@id</a>.', array(
    ':url' => $new_job
      ->toUrl()
      ->toString(),
    '@id' => $new_job
      ->id(),
  ));
  $new_job
    ->addMessage('This job is a duplicate of the previously aborted job <a href=":url">#@id</a>', array(
    ':url' => $this->entity
      ->toUrl()
      ->toString(),
    '@id' => $this->entity
      ->id(),
  ));
  $this
    ->messenger()
    ->addStatus(t('The aborted job has been duplicated. You can resubmit it now.'));
  $form_state
    ->setRedirectUrl($new_job
    ->toUrl());
}