function LayoutBuilderOptInTest::getPathForFieldBlock

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderOptInTest::getPathForFieldBlock()
  2. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderOptInTest::getPathForFieldBlock()
  3. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderOptInTest::getPathForFieldBlock()

Returns the path to update a field block in the UI.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle.

string $view_mode: The view mode.

string $field_name: The field name.

Return value

string The path.

1 call to LayoutBuilderOptInTest::getPathForFieldBlock()
LayoutBuilderOptInTest::testDefaultValues in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php
Tests the expected default values for enabling Layout Builder.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderOptInTest.php, line 175

Class

LayoutBuilderOptInTest
Tests the ability for opting in and out of Layout Builder.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function getPathForFieldBlock($entity_type_id, $bundle, $view_mode, $field_name) : string {
    $delta = 0;
    
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display */
    $display = $this->container
        ->get('entity_type.manager')
        ->getStorage('entity_view_display')
        ->load("{$entity_type_id}.{$bundle}.{$view_mode}");
    $body_component = NULL;
    foreach ($display->getSection($delta)
        ->getComponents() as $component) {
        if ($component->getPluginId() === "field_block:{$entity_type_id}:{$bundle}:{$field_name}") {
            $body_component = $component;
        }
    }
    $this->assertNotNull($body_component);
    return 'layout_builder/update/block/defaults/node.after.default/0/content/' . $body_component->getUuid();
}

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