You are here

protected function JobItemForm::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

File

src/Form/JobItemForm.php, line 174

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',
      ],
    ];
  }
  $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;
}