createMediaItems example


  protected $mediaItems = [];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a few example media items for use in selection.     $this->mediaItems = $this->createMediaItems([
      'type_one' => [
        'Horse',
        'Bear',
        'Cat',
        'Dog',
      ],
      'type_two' => [
        'Crocodile',
        'Lizard',
        'Snake',
        'Turtle',
      ],
$this->drupalPlaceBlock('local_tasks_block');

    // Create a user who can add media fields.     $user = $this->drupalCreateUser([
      'access administration pages',
      'administer node fields',
      'administer node form display',
    ]);
    $this->drupalLogin($user);
    $this->drupalCreateContentType(['type' => 'article']);
    $this->drupalCreateContentType(['type' => 'page']);
    $this->createMediaItems([
      'type_one' => [
        'Horse',
        'Bear',
        'Cat',
        'Dog',
      ],
    ]);
  }

  /** * Tests field UI integration for media library widget. */

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a few example media items for use in selection.     $this->createMediaItems([
      'type_one' => [
        'Cat',
        'Dog',
      ],
    ]);

    // Allow the anonymous user to create pages and view media.     $role = Role::load(RoleInterface::ANONYMOUS_ID);
    $this->grantPermissions($role[
      'access content',
      'create basic_page content',
      

  protected $defaultTheme = 'stark';

  /** * Tests that the widget access works as expected. */
  public function testWidgetAccess() {
    $assert_session = $this->assertSession();
    $session = $this->getSession();

    $this->createMediaItems([
      'type_one' => ['Horse', 'Bear'],
    ]);
    $account = $this->drupalCreateUser(['create basic_page content']);
    $this->drupalLogin($account);

    // Assert users can not select media items they do not have access to.     $unpublished_media = Media::create([
      'name' => 'Mosquito',
      'bundle' => 'type_one',
      'field_media_test' => 'Mosquito',
      'status' => FALSE,
    ]);

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a few example media items for use in selection.     $this->createMediaItems([
      'type_one' => [
        'Horse',
        'Bear',
        'Cat',
        'Dog',
        'Goat',
        'Sheep',
        'Pig',
        'Cow',
        'Chicken',
        'Duck',
        

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a few example media items for use in selection.     $this->createMediaItems([
      'type_one' => [
        'Horse',
        'Bear',
        'Cat',
        'Dog',
      ],
      'type_two' => [
        'Crocodile',
        'Lizard',
        'Snake',
        'Turtle',
      ],

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Create a few example media items for use in selection.     $this->createMediaItems([
      'type_one' => [
        'Horse',
        'Bear',
        'Cat',
        'Dog',
      ],
      'type_two' => [
        'Crocodile',
        'Lizard',
        'Snake',
        'Turtle',
      ],
Home | Imprint | This part of the site doesn't use cookies.