You are here

public static function InsertFileWidgetUtility::validateClass in Insert 8

Cleans the class input removing any redundant whitespace.

Parameters

array $element:

\Drupal\Core\Form\FormState $form_state:

File

src/Utility/InsertFileWidgetUtility.php, line 126

Class

InsertFileWidgetUtility

Namespace

Drupal\insert\Utility

Code

public static function validateClass($element, &$form_state) {
  $trimmedClasses = [];
  foreach (explode(' ', $element['#value']) as $class) {
    $class = trim($class);
    if ($class !== '') {
      $trimmedClasses[] = $class;
    }
  }
  $form_state
    ->setValueForElement($element, join(' ', $trimmedClasses));
}