You are here

protected function FileUploadForm::buildInputElement in Media Directories 8

Same name and namespace in other branches
  1. 3.x modules/media_directories_ui/src/Form/FileUploadForm.php \Drupal\media_directories_ui\Form\FileUploadForm::buildInputElement()
  2. 2.x modules/media_directories_ui/src/Form/FileUploadForm.php \Drupal\media_directories_ui\Form\FileUploadForm::buildInputElement()

Inheriting classes need to build the desired input element.

Overrides AddMediaFormBase::buildInputElement

1 method overrides FileUploadForm::buildInputElement()
MediaCombinedUploadForm::buildInputElement in modules/media_directories_ui/src/Form/MediaCombinedUploadForm.php
Inheriting classes need to build the desired input element.

File

modules/media_directories_ui/src/Form/FileUploadForm.php, line 71

Class

FileUploadForm
A form to upload files.

Namespace

Drupal\media_directories_ui\Form

Code

protected function buildInputElement(array $form, FormStateInterface $form_state) {
  $media_type = $this
    ->getMediaType($form_state);
  $source_field = $media_type
    ->getSource()
    ->getConfiguration()['source_field'];
  $field_config = $this->entityTypeManager
    ->getStorage('field_config')
    ->load('media.' . $media_type
    ->id() . '.' . $source_field);
  $process = (array) $this->elementInfo
    ->getInfoProperty('managed_file', '#process', []);
  $pre_render = (array) $this->elementInfo
    ->getInfoProperty('managed_file', '#pre_render', []);
  $form['container']['upload'] = [
    '#type' => 'managed_file',
    '#title' => $field_config
      ->label(),
    '#description' => $this
      ->t('Allowed file extensions: @extensions', [
      '@extensions' => $field_config
        ->getSetting('file_extensions'),
    ]),
    '#upload_validators' => $this
      ->getUploadValidators($media_type),
    '#multiple' => TRUE,
    '#upload_location' => $this
      ->getUploadLocation($field_config
      ->getSettings()),
    '#process' => array_merge([
      '::validateUploadElement',
    ], $process, [
      '::processUploadElement',
    ]),
    '#pre_render' => array_merge($pre_render, [
      [
        static::class,
        'preRenderUploadElement',
      ],
    ]),
  ];
  return $form;
}