You are here

public function SchedulerMediaSetupTrait::createMediaItem in Scheduler 2.x

Creates a media entity.

Parameters

array $values: The values to use for the entity.

Return value

\Drupal\media\MediaInterface The created media object.

2 calls to SchedulerMediaSetupTrait::createMediaItem()
SchedulerBasicMediaTest::testMediaPublishing in tests/src/Functional/SchedulerBasicMediaTest.php
Tests scheduled publishing of a media entity.
SchedulerBasicMediaTest::testMediaUnpublishing in tests/src/Functional/SchedulerBasicMediaTest.php
Tests scheduled unpublishing of a media entity.

File

tests/src/Traits/SchedulerMediaSetupTrait.php, line 144

Class

SchedulerMediaSetupTrait
Additional setup trait for Scheduler tests that use Media.

Namespace

Drupal\Tests\scheduler\Traits

Code

public function createMediaItem(array $values) {

  // Provide defaults for the critical values.
  $values += [
    'bundle' => $this->mediaTypeName,
    'name' => $this
      ->randomstring(12),
  ];

  /** @var \Drupal\media\MediaInterface $media */
  $media = $this->mediaStorage
    ->create($values);
  $media
    ->save();
  return $media;
}