function uikit_preprocess_input

8.x-3.x preprocess.inc uikit_preprocess_input(&$variables)
8.x-2.x preprocess.inc uikit_preprocess_input(&$variables)

File

includes/preprocess.inc, line 293
Set up variables to be placed within the template (.html.twig) files.

Code

function uikit_preprocess_input(&$variables) {
  $element = $variables ['element'];

  if (isset($element ['#parents']) && isset($element ['#errors']) && !empty($element ['#validated'])) {
    $variables ['attributes']['class'][] = 'uk-form-danger';
  }

  switch ($element ['#type']) {
    case 'email':
    case 'number':
    case 'password':
    case 'search':
    case 'tel':
    case 'textfield':
    case 'url':
      $variables ['attributes']['class'][] = 'uk-input';
      break;

    case 'checkbox':
      $variables ['attributes']['class'][] = 'uk-checkbox';
      break;

    case 'date':
      $variables ['attributes']['class'][] = 'uk-input';
      $variables ['attributes']['class'][] = 'uk-form-small';
      $variables ['attributes']['class'][] = 'uk-form-width-medium';
      break;

    case 'hidden':
      $variables ['attributes']['class'][] = 'uk-margin';
      break;

    case 'radio':
      $variables ['attributes']['class'][] = 'uk-radio';
      break;

    case 'range':
      $variables ['attributes']['class'][] = 'uk-range';
      break;

    case 'button':
    case 'submit':
      $variables ['attributes']['class'][] = 'uk-button';
      break;
  }

  if ($element ['#type'] == 'button' || $element ['#type'] == 'submit') {
    if (is_object($variables ['element']['#value'])) {
      $value = $variables ['element']['#value']->__toString();
    }
    else {
      $value = $variables ['element']['#value'];
    }

    switch (TRUE) {
      case preg_match('/Apply.*/', $value):
      case preg_match('/Filter.*/', $value):
      case preg_match('/Generate.*/', $value):
      case preg_match('/Install.*/', $value):
      case preg_match('/Save.*/', $value):
        $variables ['attributes']['class'][] = 'uk-button-primary';
        break;

      case preg_match('/Delete.*/', $value):
      case preg_match('/Remove.*/', $value):
        $variables ['attributes']['class'][] = 'uk-button-danger';
        break;

      default:
        $variables ['attributes']['class'][] = 'uk-button-default';
    }
  }
}

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Log in