function FieldUiAssertTrait::getFieldFromGroup

Same name and namespace in other branches
  1. 11.x core/modules/field_ui/tests/src/Traits/FieldUiAssertTrait.php \Drupal\Tests\field_ui\Traits\FieldUiAssertTrait::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|null Group name

File

core/modules/field_ui/tests/src/Traits/FieldUiAssertTrait.php, line 21

Class

FieldUiAssertTrait
Provides assertions and helpers for Field UI test classes.

Namespace

Drupal\Tests\field_ui\Traits

Code

protected function getFieldFromGroup($field_type) : ?string {
  /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager */
  $field_type_plugin_manager = \Drupal::service('plugin.manager.field.field_type');
  $grouped_field_types = $field_type_plugin_manager->getGroupedDefinitions($field_type_plugin_manager->getUiDefinitions());
  foreach ($grouped_field_types as $group => $field_types) {
    if (array_key_exists($field_type, $field_types)) {
      return $group;
    }
  }
  return NULL;
}

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