public function MediaHelper::createFromInput in Lightning Media 8
Same name and namespace in other branches
- 8.4 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::createFromInput()
- 8.2 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::createFromInput()
- 8.3 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::createFromInput()
Creates a media entity from an input value.
Parameters
mixed $value: The input value.
string[] $bundles: (optional) A set of media bundle IDs which might match the input value. If omitted, all bundles to which the user has create access are checked.
Return value
\Drupal\media\MediaInterface The unsaved media entity.
File
- src/
MediaHelper.php, line 119
Class
- MediaHelper
- Provides helper methods for dealing with media entities.
Namespace
Drupal\lightning_mediaCode
public function createFromInput($value, array $bundles = []) {
/** @var \Drupal\media\MediaInterface $entity */
$entity = $this->entityTypeManager
->getStorage('media')
->create([
'bundle' => $this
->getBundleFromInput($value, TRUE, $bundles)
->id(),
]);
$field = static::getSourceField($entity);
if ($field) {
$field
->setValue($value);
}
return $entity;
}