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. 8.9.x core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::createFileItem()
  3. 10 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
FileUploadForm::createMediaFromValue in core/modules/media_library/src/Form/FileUploadForm.php

File

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

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.