function protected static function ProcessManager::processInputGroups

8.x-3.x ProcessManager.php protected static ProcessManager::processInputGroups(Element $element, FormStateInterface $form_state, array &$complete_form)

Processes elements that have input groups.

Parameters

\Drupal\bootstrap\Utility\Element $element: The element object.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

Class

ProcessManager
Manages discovery and instantiation of Bootstrap form process callbacks.

Namespace

Drupal\bootstrap\Plugin

Source src/Plugin/ProcessManager.php (line 148)

protected static function processInputGroups(Element $element, FormStateInterface $form_state, array &$complete_form) {
  // Automatically inject the nearest button found after this element if
  // #input_group_button exists.
  if ($element->getProperty('input_group_button')) {
    // Obtain the parent array to limit search.
    $array_parents = $element->getProperty('array_parents', []);

    // Remove the current element from the array.
    array_pop($array_parents);

    // Retrieve the parent element.
    $parent = Element::create(NestedArray::getValue($complete_form, $array_parents), $form_state);

    // Find the closest button.
    if ($button = & $parent->findButton()) {
      // Since this button is technically being "moved", it needs to be
      // rendered now, so it doesn't get printed twice (in the original spot).
      $element->appendProperty('field_suffix', $button->setIcon()->render());
    }
  }

  $input_group_attributes = ['class' => ['input-group-' . ($element->getProperty('input_group_button') ? 'btn' : 'addon')]];
  if ($prefix = $element->getProperty('field_prefix')) {
    $element->setProperty('field_prefix', [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#attributes' => $input_group_attributes,
      '#value' => Element::create($prefix)->renderPlain(),
      '#weight' => -1,
    ]);
  }
  if ($suffix = $element->getProperty('field_suffix')) {
    $element->setProperty('field_suffix', [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#attributes' => $input_group_attributes,
      '#value' => Element::create($suffix)->renderPlain(),
      '#weight' => 1,
    ]);
  }
}