You are here

public static function PrettyElement::process in Pretty Checkbox Radio 8

Processes checkboxes and radios form element.

File

src/PrettyElement.php, line 15

Class

PrettyElement
Provides methods for Drupal render pretty elements.

Namespace

Drupal\pcr

Code

public static function process(&$element, FormStateInterface $form_state, &$complete_form) {

  // If the element to be processed has the #pretty_option widget.
  if (isset($element['#pretty_option'])) {

    // Check if the current element is Boolean or List text type.
    switch ($element['#type']) {
      case 'checkbox':
      case 'radio':

        // Modify the current element to change it to pretty element.
        $element = self::setValues($element);
        break;
      case 'checkboxes':
      case 'radios':
        if (isset($element['#options']) && count($element['#options']) > 0) {
          foreach ($element['#options'] as $key => $choice) {

            // Modify the current element to change it to pretty element.
            $element[$key] = self::setValues($element[$key]);
          }
        }
        break;
    }
  }
  return $element;
}