You are here

public function WorkspaceDeployForm::actions in Drupal 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

core/modules/workspaces/src/Form/WorkspaceDeployForm.php, line 115

Class

WorkspaceDeployForm
Provides the workspace deploy form.

Namespace

Drupal\workspaces\Form

Code

public function actions(array $form, FormStateInterface $form_state) {
  $elements = parent::actions($form, $form_state);
  unset($elements['delete']);
  $workspace_publisher = $this->workspaceOperationFactory
    ->getPublisher($this->entity);
  if (isset($form['deploy'])) {
    $total_count = $form['deploy']['#total_count'];
    $elements['submit']['#value'] = $this
      ->formatPlural($total_count, 'Deploy @count item to @target', 'Deploy @count items to @target', [
      '@target' => $workspace_publisher
        ->getTargetLabel(),
    ]);
    $elements['submit']['#submit'] = [
      '::submitForm',
      '::deploy',
    ];
  }
  else {

    // Do not allow the 'Deploy' operation if there's nothing to push.
    $elements['submit']['#value'] = $this
      ->t('Deploy');
    $elements['submit']['#disabled'] = TRUE;
  }
  $elements['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#attributes' => [
      'class' => [
        'button',
      ],
    ],
    '#url' => $this->entity
      ->toUrl('collection'),
  ];
  return $elements;
}