You are here

public static function EditorIconDialog::validatePowerTransforms in Font Awesome Icons 8.2

Validate the Font Awesome power transforms.

File

src/Form/EditorIconDialog.php, line 347

Class

EditorIconDialog
Provides a Font Awesome icon dialog for text editors.

Namespace

Drupal\fontawesome\Form

Code

public static function validatePowerTransforms($element, FormStateInterface $form_state) {
  $value = $element['#value'];
  if (strlen($value) == 0) {
    $form_state
      ->setValueForElement($element, '');
    return;
  }

  // Check the value of the power transform.
  $transformSettings = $form_state
    ->getValues();
  foreach (array_slice($element['#parents'], 0, 3) as $key) {
    $transformSettings = $transformSettings[$key];
  }
  if (!is_numeric($transformSettings['value'])) {
    $form_state
      ->setError($element, t("Invalid value for Font Awesome Power Transform %value. Please see @iconLink for information on correct values.", [
      '%value' => $value,
      '@iconLink' => Link::fromTextAndUrl(t('the Font Awesome guide to Power Transforms'), Url::fromUri('https://fontawesome.com/how-to-use/on-the-web/styling/power-transforms'))
        ->toString(),
    ]));
  }
}