function MediaTypeForm::actions

Same name and namespace in other branches
  1. 9 core/modules/media/src/MediaTypeForm.php \Drupal\media\MediaTypeForm::actions()
  2. 8.9.x core/modules/media/src/MediaTypeForm.php \Drupal\media\MediaTypeForm::actions()
  3. 10 core/modules/media/src/MediaTypeForm.php \Drupal\media\MediaTypeForm::actions()

Overrides EntityForm::actions

File

core/modules/media/src/MediaTypeForm.php, line 325

Class

MediaTypeForm
Form controller for media type forms.

Namespace

Drupal\media

Code

protected function actions(array $form, FormStateInterface $form_state) {
    $actions = parent::actions($form, $form_state);
    // If the media source has not been chosen yet, turn the submit button into
    // a button. This rebuilds the form with the media source's configuration
    // form visible, instead of saving the media type. This allows users to
    // create a media type without JavaScript enabled. With JavaScript enabled,
    // this rebuild occurs during an AJAX request.
    // @see \Drupal\media\MediaTypeForm::ajaxHandlerData()
    if (empty($this->getEntity()
        ->get('source'))) {
        $actions['submit']['#type'] = 'button';
    }
    $actions['submit']['#value'] = $this->t('Save');
    $actions['delete']['#value'] = $this->t('Delete');
    $actions['delete']['#access'] = $this->entity
        ->access('delete');
    return $actions;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.