You are here

protected static function ProcessManager::processInputGroups in Express 8

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.

1 call to ProcessManager::processInputGroups()
ProcessManager::process in themes/contrib/bootstrap/src/Plugin/ProcessManager.php
Global #process callback for form elements.

File

themes/contrib/bootstrap/src/Plugin/ProcessManager.php, line 113
Contains \Drupal\bootstrap\Plugin\ProcessManager.

Class

ProcessManager
Manages discovery and instantiation of Bootstrap form process callbacks.

Namespace

Drupal\bootstrap\Plugin

Code

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 = self::findButton($parent)) {

      // 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,
    ]);
  }
}