function MediaLibraryTestBase::createMediaItems
Same name in other branches
- 8.9.x core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::createMediaItems()
- 10 core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::createMediaItems()
- 11.x core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::createMediaItems()
Create media items.
Parameters
array $media_items: A nested array of media item names keyed by media type.
Return value
\Drupal\media\MediaInterface[] An array of media entities keyed by the names passed in.
6 calls to MediaLibraryTestBase::createMediaItems()
- EntityReferenceWidgetTest::setUp in core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ EntityReferenceWidgetTest.php - MediaOverviewTest::setUp in core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ MediaOverviewTest.php - ViewsUiIntegrationTest::setUp in core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ ViewsUiIntegrationTest.php - WidgetAccessTest::testWidgetAccess in core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ WidgetAccessTest.php - Tests that the widget access works as expected.
- WidgetAnonymousTest::setUp in core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ WidgetAnonymousTest.php
File
-
core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ MediaLibraryTestBase.php, line 32
Class
- MediaLibraryTestBase
- Base class for functional tests of Media Library functionality.
Namespace
Drupal\Tests\media_library\FunctionalJavascriptCode
protected function createMediaItems(array $media_items) {
$created_items = [];
$time = time();
foreach ($media_items as $type => $names) {
foreach ($names as $name) {
/** @var \Drupal\media\MediaInterface $media */
$media = Media::create([
'name' => $name,
'bundle' => $type,
]);
$source_field = $media->getSource()
->getSourceFieldDefinition($media->bundle->entity)
->getName();
$media->set($source_field, $name)
->setCreatedTime(++$time)
->save();
$created_items[$name] = $media;
}
}
return $created_items;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.