function FieldBlockDeriverTest::testFieldBlockDerivers

Same name in other branches
  1. 10 core/modules/layout_builder/tests/src/Kernel/FieldBlockDeriverTest.php \Drupal\Tests\layout_builder\Kernel\FieldBlockDeriverTest::testFieldBlockDerivers()

Tests that field block derivers respect expose_all_field_blocks config.

When expose_all_field_blocks is disabled (the default setting), only bundles that have layout builder enabled will expose their fields as field blocks.

File

core/modules/layout_builder/tests/src/Kernel/FieldBlockDeriverTest.php, line 33

Class

FieldBlockDeriverTest
Tests field block plugin derivatives.

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testFieldBlockDerivers() : void {
    $plugins = $this->getBlockPluginIds();
    // Setting is disabled and entity_test bundles do not have layout builder
    // configured.
    $this->assertNotContains('field_block:user:user:name', $plugins);
    $this->assertNotContains('extra_field_block:user:user:member_for', $plugins);
    $this->assertNotContains('field_block:entity_test:entity_test:id', $plugins);
    // Enabling layout builder for entity_test adds field blocks for entity_test
    // bundles, but not for the user entity type.
    $display = LayoutBuilderEntityViewDisplay::create([
        'targetEntityType' => 'entity_test',
        'bundle' => 'entity_test',
        'mode' => 'default',
        'status' => TRUE,
        'third_party_settings' => [
            'layout_builder' => [
                'enabled' => TRUE,
            ],
        ],
    ]);
    $display->save();
    $plugins = $this->getBlockPluginIds();
    $this->assertContains('field_block:entity_test:entity_test:id', $plugins);
    $this->assertNotContains('field_block:user:user:name', $plugins);
    $this->assertNotContains('extra_field_block:user:user:member_for', $plugins);
    // Exposing all field blocks adds them for the user entity type.
    \Drupal::service('module_installer')->install([
        'layout_builder_expose_all_field_blocks',
    ]);
    $plugins = $this->getBlockPluginIds();
    $this->assertContains('field_block:user:user:name', $plugins);
    $this->assertContains('extra_field_block:user:user:member_for', $plugins);
}

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