You are here

public static function ScssColor::processColor in SCSS Compiler 1.0.x

Process the element before it gets rendered in the form.

Parameters

array $element: The element to process before being rendered.

\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.

File

src/Element/ScssColor.php, line 74

Class

ScssColor
A form element to represent null-able Sass colors.

Namespace

Drupal\compiler_scss\Element

Code

public static function processColor(array &$element, FormStateInterface $form_state, array &$complete_form) {
  $element['enable'] = [
    '#type' => 'checkbox',
    '#title' => t('Set value?'),
    '#name' => "{$element['#name']}[enable]",
    '#access' => !$element['#required'],
    '#default_value' => !empty(self::getValue($element)),
  ];
  $element['value'] = [
    '#type' => 'color',
    '#name' => "{$element['#name']}[value]",
    '#title' => $element['#title'],
    '#title_display' => 'none',
    // The "color" element only supports hex codes with long channels and no
    // alpha channel value, so we trim the value here.
    '#default_value' => substr(self::getValue($element), 0, 7),
    '#required' => $element['#required'],
    '#states' => [
      'visible' => [
        ":input[name=\"{$element['enable']['#name']}\"]" => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['#children'][] =& $element['enable'];
  $element['#children'][] =& $element['value'];
  return $element;
}