EntityForm::actions

protected EntityForm::actions(array $form, FormStateInterface $form_state)

Returns an array of supported actions for the current entity form.

@todo Consider introducing a 'preview' action here, since it is used by many entity types.

File

core/lib/Drupal/Core/Entity/EntityForm.php, line 225

Class

EntityForm
Base class for entity forms.

Namespace

Drupal\Core\Entity

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
protected function actions(array $form, FormStateInterface $form_state) {
  // @todo Consider renaming the action key from submit to save. The impacts
  //   are hard to predict. For example, see
  //   \Drupal\language\Element\LanguageConfiguration::processLanguageConfiguration().
  $actions['submit'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Save'),
    '#submit' => array('::submitForm', '::save'),
  );
 
  if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('delete-form')) {
    $route_info = $this->entity->urlInfo('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'] = array(
      '#type' => 'link',
      '#title' => $this->t('Delete'),
      '#access' => $this->entity->access('delete'),
      '#attributes' => array(
        'class' => array('button', 'button--danger'),
      ),
    );
    $actions['delete']['#url'] = $route_info;
  }
 
  return $actions;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.