You are here

protected function DynamicLayoutForm::actions in Dynamic Layouts 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/DynamicLayoutForm.php, line 332

Class

DynamicLayoutForm
Form controller for the DynamicLayout entity edit forms.

Namespace

Drupal\dynamic_layouts\Form

Code

protected function actions(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\dynamic_layouts\Entity\DynamicLayout $entity */
  $entity = $this->entity;

  // Change submit button title if entity is new.
  $submit_title = $this
    ->t('Save layout');
  if ($entity
    ->isNew()) {
    $submit_title = $this
      ->t('Save and configure rows');
  }

  // Set the custom submit title.
  $actions['submit'] = [
    '#type' => 'submit',
    '#value' => $submit_title,
    '#submit' => [
      '::submitForm',
      '::save',
    ],
  ];
  if (!$this->entity
    ->isNew() && $this->entity
    ->hasLinkTemplate('delete-form')) {
    $route_info = $this->entity
      ->toUrl('delete-form');
    if ($this
      ->getRequest()->query
      ->has('destination')) {
      $query = $route_info
        ->getOption('query');
      $query['destination'] = $this
        ->getRequest()->query
        ->get('destination');
      $route_info
        ->setOption('query', $query);
    }
    $actions['delete'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Delete'),
      '#access' => $this->entity
        ->access('delete'),
      '#attributes' => [
        'class' => [
          'button',
          'button--danger',
        ],
      ],
    ];
    $actions['delete']['#url'] = $route_info;
  }
  return $actions;
}