Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public function JobForm::save

Overrides Drupal\Core\Entity\EntityForm::save().

1 call to JobForm::save()
1 method overrides JobForm::save()

File

src/Form/JobForm.php, line 637

Class

JobForm
Form controller for the job edit forms.

Namespace

Drupal\tmgmt\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  parent::save($form, $form_state);

  // Everything below this line is only invoked if the 'Submit to provider'
  // button was clicked.
  if (isset($form['actions']['submit']) && $form_state
    ->getTriggeringElement()['#value'] == $form['actions']['submit']['#value']) {
    if ($this->entity
      ->get('label')
      ->isEmpty()) {
      $this->entity
        ->set('label', $this->entity
        ->label());
    }

    // Delete conflicting items.
    $storage = \Drupal::entityTypeManager()
      ->getStorage('tmgmt_job_item');
    if ($existing_items_ids = $form_state
      ->get('existing_item_ids')) {
      $storage
        ->delete($storage
        ->loadMultiple($existing_items_ids));
      $num_of_items = count($existing_items_ids);
      $this
        ->messenger()
        ->addWarning(\Drupal::translation()
        ->formatPlural($num_of_items, '1 conflicting item has been dropped.', '@count conflicting items have been dropped.'));
    }
    if ($form_state
      ->getValue('submit_all')) {
      $this
        ->getRequest()->query
        ->remove('destination');
      $batch = array(
        'title' => t('Submitting jobs'),
        'operations' => [],
        'finished' => [
          JobCheckoutManager::class,
          'batchSubmitFinished',
        ],
      );
      foreach ($this->jobQueue
        ->getAllJobs() as $job) {
        $batch['operations'][] = [
          [
            JobCheckoutManager::class,
            'batchSubmit',
          ],
          [
            $job
              ->id(),
            $this->entity
              ->id(),
          ],
        ];
      }
      batch_set($batch);
      return;
    }
    if (!$this->jobCheckoutManager
      ->requestTranslation($this->entity)) {

      // Don't redirect the user if the translation request failed but retain
      // existing destination parameters so we can redirect once the request
      // finished successfully.
      $this
        ->getRequest()->query
        ->remove('destination');
      return;
    }
    else {
      $this->jobQueue
        ->markJobAsProcessed($this->entity);
    }
    if ($redirect = $this->jobQueue
      ->getNextUrl()) {

      // Proceed to the next redirect queue item, if there is one.
      $form_state
        ->setRedirectUrl($redirect);
    }
    elseif ($destination = $this->jobQueue
      ->getDestination()) {

      // Proceed to the defined destination if there is one.
      $form_state
        ->setRedirectUrl(Url::fromUri('base:' . $destination));
    }
    else {

      // Per default we want to redirect the user to the overview.
      $form_state
        ->setRedirect('view.tmgmt_job_overview.page_1');
    }
  }
  else {

    // Per default we want to redirect the user to the overview.
    $form_state
      ->setRedirect('view.tmgmt_job_overview.page_1');
  }
}