function FieldUiJSTestTrait::getFieldFromGroupJS

Same name in other branches
  1. 10 core/modules/field_ui/tests/src/Traits/FieldUiJSTestTrait.php \Drupal\Tests\field_ui\Traits\FieldUiJSTestTrait::getFieldFromGroupJS()

Helper function that returns the field card element if it is in a group.

Parameters

string $field_type: The name of the field type.

Return value

\Behat\Mink\Element\NodeElement|false|mixed|null Field card element within a group.

1 call to FieldUiJSTestTrait::getFieldFromGroupJS()
FieldUiJSTestTrait::fieldUIAddNewFieldJS in core/modules/field_ui/tests/src/Traits/FieldUiJSTestTrait.php
Creates a new field through the Field UI.

File

core/modules/field_ui/tests/src/Traits/FieldUiJSTestTrait.php, line 134

Class

FieldUiJSTestTrait
Provides common functionality for the Field UI tests that depend on JS.

Namespace

Drupal\Tests\field_ui\Traits

Code

public function getFieldFromGroupJS($field_type) {
    $group_elements = $this->getSession()
        ->getPage()
        ->findAll('css', '.field-option-radio');
    $groups = [];
    foreach ($group_elements as $group_element) {
        $groups[] = $group_element->getAttribute('value');
    }
    $field_card = NULL;
    foreach ($groups as $group) {
        $group_field_card = $this->getSession()
            ->getPage()
            ->find('css', "[name='new_storage_type'][value='{$group}']")
            ->getParent();
        $group_field_card->click();
        $this->getSession()
            ->getPage()
            ->pressButton('Continue');
        $field_card = $this->getSession()
            ->getPage()
            ->find('css', "[name='group_field_options_wrapper'][value='{$field_type}']");
        if ($field_card) {
            break;
        }
        $this->getSession()
            ->getPage()
            ->pressButton('Back');
    }
    return $field_card->getParent();
}

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