function MediaForm::form

Same name in other branches
  1. 8.9.x core/modules/media/src/MediaForm.php \Drupal\media\MediaForm::form()
  2. 10 core/modules/media/src/MediaForm.php \Drupal\media\MediaForm::form()
  3. 11.x core/modules/media/src/MediaForm.php \Drupal\media\MediaForm::form()

Overrides ContentEntityForm::form

File

core/modules/media/src/MediaForm.php, line 18

Class

MediaForm
Form controller for the media edit forms.

Namespace

Drupal\media

Code

public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    
    /** @var \Drupal\media\MediaTypeInterface $media_type */
    $media_type = $this->entity->bundle->entity;
    if ($this->operation === 'edit') {
        $form['#title'] = $this->t('Edit %type_label @label', [
            '%type_label' => $media_type->label(),
            '@label' => $this->entity
                ->label(),
        ]);
    }
    // Media author information for administrators.
    if (isset($form['uid']) || isset($form['created'])) {
        $form['author'] = [
            '#type' => 'details',
            '#title' => $this->t('Authoring information'),
            '#group' => 'advanced',
            '#attributes' => [
                'class' => [
                    'media-form-author',
                ],
            ],
            '#weight' => 90,
            '#optional' => TRUE,
        ];
    }
    if (isset($form['uid'])) {
        $form['uid']['#group'] = 'author';
    }
    if (isset($form['created'])) {
        $form['created']['#group'] = 'author';
    }
    $form['#attached']['library'][] = 'media/form';
    return $form;
}

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