function MediaLibraryDisplayModeTest::assertFormDisplay

Same name in other branches
  1. 9 core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php \Drupal\Tests\media_library\Functional\MediaLibraryDisplayModeTest::assertFormDisplay()
  2. 8.9.x core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php \Drupal\Tests\media_library\Functional\MediaLibraryDisplayModeTest::assertFormDisplay()
  3. 10 core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php \Drupal\Tests\media_library\Functional\MediaLibraryDisplayModeTest::assertFormDisplay()

Asserts the media library form display components for a media type.

@internal

Parameters

string $type_id: The media type ID.

bool $has_name: Whether the media library form display should contain the name field or not.

bool $has_source_field: Whether the media library form display should contain the source field or not.

1 call to MediaLibraryDisplayModeTest::assertFormDisplay()
MediaLibraryDisplayModeTest::testDisplayModes in core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php
Tests that the Media Library can automatically configure display modes.

File

core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php, line 237

Class

MediaLibraryDisplayModeTest
Tests that the Media Library automatically configures form/view modes.

Namespace

Drupal\Tests\media_library\Functional

Code

protected function assertFormDisplay(string $type_id, bool $has_name, bool $has_source_field) : void {
    // These components are added by default and invisible.
    $components = [
        'revision_log_message',
        'langcode',
    ];
    // Only assert the name and source field if needed.
    if ($has_name) {
        $components[] = 'name';
    }
    if ($has_source_field) {
        $type = MediaType::load($type_id);
        $components[] = $type->getSource()
            ->getSourceFieldDefinition($type)
            ->getName();
    }
    $form_display = EntityFormDisplay::load('media.' . $type_id . '.media_library');
    $this->assertInstanceOf(EntityFormDisplay::class, $form_display);
    $actual_components = array_keys($form_display->getComponents());
    sort($components);
    sort($actual_components);
    $this->assertSame($components, $actual_components);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.