selectMediaItem example

'create basic_page content',
      'view media',
    ]);

    // Ensure the widget works as an anonymous user.     $this->drupalGet('node/add/basic_page');

    // Add to the unlimited cardinality field.     $this->openMediaLibraryForField('field_unlimited_media');

    // Select the first media item (should be Dog).     $this->selectMediaItem(0);
    $this->pressInsertSelected('Added one media item.');

    // Ensure that the selection completed successfully.     $this->waitForText('Dog');
    $assert_session->fieldNotExists('Weight');

    // Add to the unlimited cardinality field.     $this->openMediaLibraryForField('field_unlimited_media');

    // Select the second media item (should be Cat).     $this->selectMediaItem(1);
    
    $assert_session->pageTextNotContains('Title field is required.');

    $this->assertTrue($menu->hasLink('Type One'));
    $this->assertTrue($menu->hasLink('Type Two'));
    $this->assertTrue($menu->hasLink('Type Three'));
    $this->assertTrue($menu->hasLink('Type Four'));
    $this->assertTrue($menu->hasLink('Type Five'));

    // Insert media to test validation with null target_bundles.     $this->switchToMediaType('One');
    $this->assertNotEmpty($assert_session->waitForText('Showing Type One media.'));
    $this->selectMediaItem(0);
    $this->pressInsertSelected('Added one media item.');

    // Assert that the media type menu is not available when only 1 type is     // configured for the field.     $this->openMediaLibraryForField('field_single_media_type', '#media-library-wrapper');
    $this->waitForElementTextContains('.media-library-selected-count', '0 of 1 item selected');

    // Select a media item, assert the hidden selection field contains the ID of     // the selected item.     $this->selectMediaItem(0);
    $assert_session->hiddenFieldValueEquals('media-library-modal-selection', '4');
    
$page->checkField('settings[handler_settings][target_bundles][type_three]');
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_three]"][checked="checked"]');
    $page->pressButton('Save settings');
    $assert_session->pageTextContains('Saved Shatner configuration.');

    $this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_shatner');
    $assert_session->checkboxNotChecked('set_default_value');
    $page->checkField('set_default_value');
    $this->assertElementExistsAfterWait('css', "#field_shatner-media-library-wrapper-default_value_input")
      ->pressButton('Add media');
    $this->waitForText('Add or select media');
    $this->selectMediaItem(0);
    $this->pressInsertSelected();

    $page->pressButton('Save settings');
    $assert_session->pageTextContains('Saved Shatner configuration.');

    $this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_shatner');
    $assert_session->checkboxChecked('set_default_value');

    // Create a new instance of an existing field storage and assert that it     // automatically uses the media library.     $this->drupalGet('/admin/structure/types/manage/page/fields/reuse');
    
Home | Imprint | This part of the site doesn't use cookies.