You are here

protected function JobForm::actions in Translation Management Tool 8

Returns an array of supported actions for the current entity form.

This function generates a list of Form API elements which represent actions supported by the current entity form.

@todo Consider introducing a 'preview' action here, since it is used by many entity types.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array An array of supported Form API action elements keyed by name.

Overrides EntityForm::actions

1 method overrides JobForm::actions()
ContinuousJobForm::actions in src/Form/ContinuousJobForm.php
Returns an array of supported actions for the current entity form.

File

src/Form/JobForm.php, line 510

Class

JobForm
Form controller for the job edit forms.

Namespace

Drupal\tmgmt\Form

Code

protected function actions(array $form, FormStateInterface $form_state) {
  $job = $this->entity;
  $actions['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save job'),
    '#submit' => array(
      '::submitForm',
      '::save',
    ),
    '#weight' => 5,
  );
  if (!$job
    ->isUnprocessed()) {
    $actions['save']['#button_type'] = 'primary';
  }
  if (!$job
    ->isContinuous() && $job
    ->access('submit')) {
    $actions['submit'] = array(
      '#type' => 'submit',
      '#button_type' => 'primary',
      '#value' => $this->jobQueue
        ->count() <= 1 ? t('Submit to provider') : t('Submit to provider and continue'),
      '#access' => $job
        ->isSubmittable(),
      '#disabled' => !$job
        ->getTranslatorId(),
      '#submit' => array(
        '::submitForm',
        '::save',
      ),
      '#weight' => 0,
    );
    $actions['resubmit_job'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'tmgmt_submit_redirect',
      ),
      '#redirect' => 'admin/tmgmt/jobs/' . $job
        ->id() . '/resubmit',
      '#value' => t('Resubmit'),
      '#access' => $job
        ->isAborted(),
      '#weight' => 10,
    );
    $actions['abort_job'] = array(
      '#type' => 'submit',
      '#value' => t('Abort job'),
      '#redirect' => 'admin/tmgmt/jobs/' . $job
        ->id() . '/abort',
      '#submit' => array(
        'tmgmt_submit_redirect',
      ),
      '#access' => $job
        ->isAbortable(),
      '#weight' => 15,
    );
  }
  else {
    $actions['save']['#button_type'] = 'primary';
  }
  if (!$job
    ->isNew()) {
    $actions['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'tmgmt_submit_redirect',
      ),
      '#redirect' => 'admin/tmgmt/jobs/' . $job
        ->id() . '/delete',
      // Don't run validations, so the user can always delete the job.
      '#limit_validation_errors' => array(),
    );
  }
  return $actions;
}