buildLibraryUi example

$image = $entity_type_manager->getStorage('media_type')->load('image');
    $remote_video = $entity_type_manager->getStorage('media_type')->load('remote_video');
    $image_source_definition = $image->getSource()->getPluginDefinition();
    $remote_video_source_definition = $remote_video->getSource()->getPluginDefinition();

    // Assert the form class is added to the media source.     $this->assertSame(FileUploadForm::class$image_source_definition['forms']['media_library_add']);
    $this->assertSame(OEmbedForm::class$remote_video_source_definition['forms']['media_library_add']);

    // Assert the media library UI does not contains the add form when the user     // does not have access.     $this->assertEmpty($this->buildLibraryUi('image')['content']['form']);
    $this->assertEmpty($this->buildLibraryUi('remote_video')['content']['form']);

    // Create a user that has access to create the image media type but not the     // remote video media type.     $this->setCurrentUser($this->createUser([
      'create image media',
    ]));
    // Assert the media library UI only contains the add form for the image     // media type.     $this->assertSame('managed_file', $this->buildLibraryUi('image')['content']['form']['container']['upload']['#type']);
    $this->assertEmpty($this->buildLibraryUi('remote_video')['content']['form']);

    
Home | Imprint | This part of the site doesn't use cookies.