protected function JobItemForm::actions

File

src/Form/JobItemForm.php, line 175

Class

JobItemForm
Form controller for the job item edit forms.

Namespace

Drupal\tmgmt\Form

Code

protected function actions(array $form, FormStateInterface $form_state) {
  $item = $this->entity;

  // Add the form actions as well.
  $actions['accept'] = array(
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => t('Save as completed'),
    '#access' => $item
      ->isNeedsReview() && !$form_state
      ->has('accept_item'),
    '#validate' => array(
      '::validateForm',
      '::validateJobItem',
    ),
    '#submit' => array(
      '::submitForm',
      '::save',
    ),
  );
  $actions['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#access' => !$item
      ->isAccepted() && !$form_state
      ->get('all_preliminary'),
    '#submit' => array(
      '::submitForm',
      '::save',
    ),
  );
  if ($item
    ->isActive()) {
    $actions['save']['#button_type'] = 'primary';
  }
  $actions['validate'] = array(
    '#type' => 'submit',
    '#value' => t('Validate'),
    '#access' => !$item
      ->isAccepted(),
    '#validate' => array(
      '::validateForm',
      '::validateJobItem',
    ),
    '#submit' => array(
      '::submitForm',
      '::submitRebuild',
    ),
  );
  $actions['validate_html'] = array(
    '#type' => 'submit',
    '#value' => t('Validate HTML tags'),
    '#access' => !$item
      ->isAccepted(),
    '#validate' => [
      '::validateTags',
    ],
    '#submit' => [
      '::submitForm',
    ],
  );
  if ($item
    ->getSourcePlugin() instanceof SourcePreviewInterface && $item
    ->getSourcePlugin()
    ->getPreviewUrl($item)) {
    $actions['preview'] = [
      '#type' => 'link',
      '#title' => t('Preview'),
      '#url' => $item
        ->getSourcePlugin()
        ->getPreviewUrl($item),
      '#attributes' => [
        'target' => '_blank',
        'class' => [
          'action-link',
        ],
      ],
    ];
  }
  $actions['abort_job_item'] = [
    '#type' => 'link',
    '#title' => t('Abort'),
    '#access' => $item
      ->isAbortable(),
    '#url' => Url::fromRoute('entity.tmgmt_job_item.abort_form', [
      'tmgmt_job_item' => $item
        ->id(),
    ]),
    '#weight' => 40,
    '#attributes' => [
      'class' => [
        'button',
        'button--danger',
      ],
    ],
  ];
  return $actions;
}