function FieldUiTestTrait::getFieldFromGroup

Same name in other branches
  1. 11.x core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php \Drupal\Tests\field_ui\Traits\FieldUiTestTrait::getFieldFromGroup()

Helper function that returns the name of the group that a field is in.

Parameters

string $field_type: The name of the field type.

Return value

string Group name

2 calls to FieldUiTestTrait::getFieldFromGroup()
FieldUiTestTrait::fieldUIAddNewField in core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php
Creates a new field through the Field UI.
ManageFieldsFunctionalTest::testHiddenFields in core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
Tests that Field UI respects the 'no_ui' flag in the field type definition.

File

core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php, line 196

Class

FieldUiTestTrait
Provides common functionality for the Field UI test classes.

Namespace

Drupal\Tests\field_ui\Traits

Code

public function getFieldFromGroup($field_type) {
    $group_elements = $this->getSession()
        ->getPage()
        ->findAll('css', '.field-option-radio');
    $groups = [];
    foreach ($group_elements as $group_element) {
        $groups[] = $group_element->getAttribute('value');
    }
    foreach ($groups as $group) {
        $test = [
            'new_storage_type' => $group,
        ];
        $this->submitForm($test, 'Continue');
        try {
            $this->assertSession()
                ->elementExists('css', "[name='group_field_options_wrapper'][value='{$field_type}']");
            $this->submitForm([], 'Back');
            return $group;
        } catch (ElementNotFoundException) {
            $this->submitForm([], 'Back');
            continue;
        }
    }
    return NULL;
}

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