You are here

protected static function ScssNumber::processUnitMultiple in SCSS Compiler 1.0.x

Add a unit select element to the composite form element.

Parameters

array $element: The element to which a unit select element should be added.

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

array $complete_form: The complete form.

Return value

array The resulting element after having been processed.

1 call to ScssNumber::processUnitMultiple()
ScssNumber::processNumber in src/Element/ScssNumber.php
Process the element before it gets rendered in the form.

File

src/Element/ScssNumber.php, line 449

Class

ScssNumber
A form element to represent Sass numbers with a unit.

Namespace

Drupal\compiler_scss\Element

Code

protected static function processUnitMultiple(array &$element, FormStateInterface $form_state, array &$complete_form) {
  $required = $element['#required'] && $element['#unit_required'];
  $default = self::getValue($element, 'unit');

  // Check if an empty option should be presented.
  $empty_option = !$required || empty($default) ? [
    '#empty_option' => t('- Unit -'),
  ] : [];

  // Display a select box for the user to pick a unit (if any).
  $element['unit'] = [
    '#type' => 'select',
    '#title' => $element['#title'],
    '#title_display' => 'none',
    '#name' => "{$element['#name']}[unit]",
    '#required' => $required,
    '#default_value' => $default,
    '#options' => $element['#unit_options'],
    '#states' => [
      'disabled' => [
        ":input[name=\"{$element['value']['#name']}\"]" => [
          'empty' => TRUE,
        ],
      ],
    ],
  ] + $empty_option;
  return $element;
}