function LayoutBuilderQuickEditTest::getQuickEditFieldId

Same name in other branches
  1. 9 core/modules/quickedit/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php \Drupal\Tests\quickedit\FunctionalJavascript\LayoutBuilderQuickEditTest::getQuickEditFieldId()
1 call to LayoutBuilderQuickEditTest::getQuickEditFieldId()
LayoutBuilderQuickEditTest::replaceLayoutBuilderFieldIdKeys in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php
Replaces the array keys with Layout Builder field IDs when needed.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderQuickEditTest.php, line 345

Class

LayoutBuilderQuickEditTest
Tests that Layout Builder functions with Quick Edit.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function getQuickEditFieldId($original_field_id) {
    $page = $this->getSession()
        ->getPage();
    $parts = explode('/', $original_field_id);
    // Removes the last part of the field id which will contain the Quick Edit
    // view mode ID. When using the Layout Builder the view_mode will contain a
    // hash of the layout sections and will be different each time the layout
    // changes.
    array_pop($parts);
    $field_key_without_view_mode = implode('/', $parts);
    $element = $page->find('css', "[data-quickedit-field-id^=\"{$field_key_without_view_mode}\"]");
    $this->assertNotEmpty($element, "Found Quick Edit-enabled field whose data-quickedit-field attribute starts with: {$field_key_without_view_mode}");
    try {
        $has_attribute = $element->hasAttribute('data-quickedit-field-id');
    } catch (\Exception $e) {
        $has_attribute = FALSE;
    }
    $this->assertTrue($has_attribute, $field_key_without_view_mode);
    $new_field_id = $element->getAttribute('data-quickedit-field-id');
    return $new_field_id;
}

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