You are here

protected function SearchApiPageForm::actions in Search API Pages 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/SearchApiPageForm.php, line 260

Class

SearchApiPageForm
Class SearchApiPageForm.

Namespace

Drupal\search_api_page\Form

Code

protected function actions(array $form, FormStateInterface $form_state) {
  $actions = parent::actions($form, $form_state);

  /* @var $search_api_page \Drupal\search_api_page\SearchApiPageInterface */
  $search_api_page = $this->entity;
  if ($search_api_page
    ->isNew()) {
    $actions['submit']['#value'] = $this
      ->t('Next');
  }
  $default_index = $search_api_page
    ->getIndex();
  if (empty($default_index)) {
    return $actions;
  }

  // Add an update button that shows up when changing the index.
  $default_index_states_invisible = [
    'invisible' => [
      ':input[name="index"]' => [
        'value' => $default_index,
      ],
    ],
  ];
  $actions['update'] = $actions['submit'];
  $actions['update']['#value'] = $this
    ->t('Update');
  $actions['update']['#states'] = $default_index_states_invisible;

  // Hide the Save button when the index changes.
  $default_index_states_visible = [
    'visible' => [
      ':input[name="index"]' => [
        'value' => $default_index,
      ],
    ],
  ];
  $actions['submit']['#states'] = $default_index_states_visible;
  return $actions;
}