protected function FieldGroupTestTrait::createGroup in Field Group 8.3
Same name and namespace in other branches
- 8 tests/src/Functional/FieldGroupTestTrait.php \Drupal\Tests\field_group\Functional\FieldGroupTestTrait::createGroup()
Create a new group.
Parameters
string $entity_type: The entity type as string.
string $bundle: The bundle of the enity type.
string $context: The context for the group.
string $mode: The view/form mode.
array $data: Data for the field group.
Return value
object An object that represents the field group.
8 calls to FieldGroupTestTrait::createGroup()
- EntityDisplayTest::testAccordion in tests/
src/ Functional/ EntityDisplayTest.php - Test the accordion formatter.
- EntityDisplayTest::testFieldAccess in tests/
src/ Functional/ EntityDisplayTest.php - Test field access for field groups.
- EntityDisplayTest::testFieldset in tests/
src/ Functional/ EntityDisplayTest.php - Test the fieldset formatter.
- EntityDisplayTest::testHtmlElement in tests/
src/ Functional/ EntityDisplayTest.php - Test the html element formatter.
- EntityDisplayTest::testTabs in tests/
src/ Functional/ EntityDisplayTest.php - Test the tabs formatter.
File
- tests/
src/ Functional/ FieldGroupTestTrait.php, line 29
Class
- FieldGroupTestTrait
- Provides common functionality for the FieldGroup test classes.
Namespace
Drupal\Tests\field_group\FunctionalCode
protected function createGroup($entity_type, $bundle, $context, $mode, array $data) {
if (!isset($data['format_settings'])) {
$data['format_settings'] = [];
}
$data['format_settings'] += Drupal::service('plugin.manager.field_group.formatters')
->getDefaultSettings($data['format_type'], $context);
$group_name_without_prefix = isset($data['group_name']) && is_string($data['group_name']) ? preg_replace('/^group_/', '', $data['group_name']) : mb_strtolower($this
->randomMachineName());
$group_name = 'group_' . $group_name_without_prefix;
$field_group = (object) [
'group_name' => $group_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'mode' => $mode,
'context' => $context,
'children' => isset($data['children']) ? $data['children'] : [],
'parent_name' => isset($data['parent']) ? $data['parent'] : '',
'weight' => isset($data['weight']) ? $data['weight'] : 0,
'label' => isset($data['label']) ? $data['label'] : $this
->randomString(8),
'format_type' => $data['format_type'],
'format_settings' => $data['format_settings'],
'region' => 'content',
];
field_group_group_save($field_group);
return $field_group;
}