You are here

public static function BackgroundImageFormTrait::createGroup in Background Image 8

Same name and namespace in other branches
  1. 2.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::createGroup()
  2. 2.0.x src/BackgroundImageFormTrait.php \Drupal\background_image\BackgroundImageFormTrait::createGroup()

Creates a new group in the form, assigning child elements as needed.

Parameters

string $key: The name to use when creating the group element in the form render array.

array $element: The render array element that the group will be added to and children are direct descendants of, passed by reference.

array $group_array: Default render array properties to use when creating the group.

array $children: Optional. An indexed array of child element keys/names that should be added to the group.

Return value

array The created group render array element, passed by reference.

3 calls to BackgroundImageFormTrait::createGroup()
BackgroundImageForm::build in src/Form/BackgroundImageForm.php
Builds the Background Image form.
BackgroundImageForm::buildSetting in src/Form/BackgroundImageForm.php
Builds a setting element.
BackgroundImageForm::buildSettings in src/Form/BackgroundImageForm.php
Builds the "Settings" group.

File

src/BackgroundImageFormTrait.php, line 269

Class

BackgroundImageFormTrait
Trait BackgroundImageFormTrait.

Namespace

Drupal\background_image

Code

public static function &createGroup($key, array &$element, array $group_array = [], array $children = []) {
  if (!isset($element[$key])) {
    $element[$key] = $group_array + [
      '#type' => 'details',
      '#title' => t(Unicode::ucfirst(trim(preg_replace('/_|-/', ' ', preg_replace('/^group/', '', $key))))),
      '#open' => TRUE,
      '#tree' => TRUE,
      '#group' => 'vertical_tabs',
      '#parents' => array_merge($element['#parents'], [
        $key,
      ]),
    ];
  }

  // Iterate over the child elements and assign them to the group.
  foreach ($children as $child) {
    if (isset($element[$child])) {
      $element[$child]['#group'] = $key;
    }
  }
  return $element[$key];
}