function FileUploadForm::createFileItem

Same name in other branches
  1. 9 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::createFileItem()
  2. 10 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::createFileItem()
  3. 11.x core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::createFileItem()

Create a file field item.

Parameters

\Drupal\media\MediaTypeInterface $media_type: The media type of the media item.

Return value

\Drupal\file\Plugin\Field\FieldType\FileItem A created file item.

2 calls to FileUploadForm::createFileItem()
FileUploadForm::buildInputElement in core/modules/media_library/src/Form/FileUploadForm.php
Builds the element for submitting source field value(s).
FileUploadForm::createMediaFromValue in core/modules/media_library/src/Form/FileUploadForm.php
Creates a new, unsaved media item from a source field value.

File

core/modules/media_library/src/Form/FileUploadForm.php, line 339

Class

FileUploadForm
Creates a form to create media entities from uploaded files.

Namespace

Drupal\media_library\Form

Code

protected function createFileItem(MediaTypeInterface $media_type) {
    $field_definition = $media_type->getSource()
        ->getSourceFieldDefinition($media_type);
    $data_definition = FieldItemDataDefinition::create($field_definition);
    return new FileItem($data_definition);
}

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