openMediaLibraryForField example

'access administration pages',
      'access content',
      'create basic_page content',
      'create type_one media',
      'create type_four media',
      'view media',
    ]);
    $this->drupalLogin($user);

    // Visit a node create page and open the media library.     $this->drupalGet('node/add/basic_page');
    $this->openMediaLibraryForField('field_twin_media');

    // Assert the upload form is not visible for default tab type_three without     // the proper permissions.     $assert_session->elementNotExists('css', '.js-media-library-add-form');

    // Assert the upload form is not visible for the non-file based media type     // type_one.     $this->switchToMediaType('One');
    $assert_session->elementNotExists('css', '.js-media-library-add-form');

    // Assert the upload form is visible for type_four.
// Visit a node create page.     $this->drupalGet('node/add/basic_page');

    // Assert that media widget instances are present.     $assert_session->pageTextContains('Unlimited media');
    $assert_session->pageTextContains('Twin media');
    $assert_session->pageTextContains('Single media type');
    $assert_session->pageTextContains('Empty types media');

    // Assert generic media library elements.     $this->openMediaLibraryForField('field_unlimited_media');
    $assert_session->elementExists('css', '.ui-dialog-titlebar-close')->click();

    // Assert that the media type menu is available when more than 1 type is     // configured for the field.     $menu = $this->openMediaLibraryForField('field_unlimited_media');
    $this->assertTrue($menu->hasLink('Show Type One media (selected)'));
    $this->assertFalse($menu->hasLink('Type Two'));
    $this->assertTrue($menu->hasLink('Type Three'));
    $this->assertFalse($menu->hasLink('Type Four'));
    $this->switchToMediaType('Three');
    // Assert the active tab is set correctly.
$youtube_url = 'https://www.youtube.com/watch?v=PWjcqE3QKBg';
    $vimeo_title = "Drupal Rap Video - Schipulcon09";
    $vimeo_url = 'https://vimeo.com/7073899';
    ResourceController::setResourceUrl($youtube_url$this->getFixturesDirectory() . '/video_youtube.json');
    ResourceController::setResourceUrl($vimeo_url$this->getFixturesDirectory() . '/video_vimeo.json');
    ResourceController::setResource404('https://www.youtube.com/watch?v=PWjcqE3QKBg1');

    // Visit a node create page.     $this->drupalGet('node/add/basic_page');

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

    // Assert the default tab for media type one does not have an oEmbed form.     $assert_session->fieldNotExists('Add Type Five via URL');

    // Assert other media types don't have the oEmbed form fields.     $this->switchToMediaType('Three');
    $assert_session->fieldNotExists('Add Type Five via URL');

    // Assert we can add an oEmbed video to media type five.     $this->switchToMediaType('Five');
    $page->fillField('Add Type Five via URL', $youtube_url);
    


  /** * Tests that the views in the Media library's widget work as expected. */
  public function testWidgetViews() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $this->drupalGet('node/add/basic_page');

    $this->openMediaLibraryForField('field_unlimited_media');

    // Assert the 'Apply filter' button is not moved to the button pane.     $button_pane = $assert_session->elementExists('css', '.ui-dialog-buttonpane');
    $assert_session->buttonExists('Insert selected', $button_pane);
    $assert_session->buttonNotExists('Apply filters', $button_pane);

    // Assert the pager works as expected.     // An active pager item is not linked and contains "Page #" as text.     $assert_session->elementTextContains('css', '.js-media-library-view .js-pager__items > li:nth-of-type(1)', 'Page 1');
    $assert_session->elementNotExists('css', '.js-media-library-view .js-pager__items > li:nth-of-type(1) a');
    $assert_session->elementExists('css', '.js-media-library-view .js-pager__items > li:nth-of-type(2) a');
    
    $role = Role::load(RoleInterface::ANONYMOUS_ID);
    $this->grantPermissions($role[
      'access content',
      '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');

    
public function testWidgetOverflow(?string $selected_operation): void {
    // If we want to press the "Save and insert" or "Save and select" buttons,     // we need to enable the advanced UI.     if ($selected_operation) {
      $this->config('media_library.settings')->set('advanced_ui', TRUE)->save();
    }

    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();
    $this->drupalGet('node/add/basic_page');
    // Upload 5 files into a media field that only allows 2.     $this->openMediaLibraryForField('field_twin_media');
    $this->uploadFiles(5);
    // Save the media items and ensure that the user is warned that they have     // selected too many items.     if ($selected_operation) {
      $this->saveAnd($selected_operation);
    }
    else {
      $this->pressSaveButton();
    }
    $this->waitForElementTextContains('.messages--warning', 'There are currently 5 items selected. The maximum number of items for the field is 2. Please remove 3 items from the selection.');
    // If the user tries to insert the selected items anyway, they should get
Home | Imprint | This part of the site doesn't use cookies.