Commit 5ff6de56 authored by Ivan Buišić's avatar Ivan Buišić
Browse files

Issue #3284406 by majmunbog: Input submit CSS classes overrides

parent ab8ccbe3
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
<?php

use Drupal\Core\Template\Attribute;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Xss;

/**
 * @file
 * Theme and preprocess functions for forms.
 */
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_theme_suggestions_HOOK_alter().
@@ -57,11 +59,15 @@ function belgrade_preprocess_input(&$variables) {
    $variables['attributes']['class'][] = 'form-check-input';
  }


  if ($type == 'submit') {

    $variables['attributes'] = new Attribute($variables['attributes']);

    if (theme_get_setting('belgrade_submit_button')) {
      $variables['submit_button'] = TRUE;
      $variables['safe_value_label'] = Xss::filter($variables['attributes']['value']);
    }

    // Get value.
    $string = $variables['attributes']->offsetGet('value')->value();

@@ -157,29 +163,32 @@ function belgrade_preprocess_input(&$variables) {
    ];

    // Check if classes are already there
    $add_white_icon = true;
    $add_white_icon = TRUE;

    foreach ($classes as $class) {
      if ($variables['attributes']->hasClass($class)) {
        $add_white_icon = false;
        $add_white_icon = FALSE;
      }
    }


    //  Iterate over the array.
    foreach ($text_data as $pattern => $strings) {
      foreach ($strings as $text => $class) {
        switch ($pattern) {
          case 'matches':
            if ($string === $text) {
              if (!$variables['attributes']->hasClass('btn-' . $class)) {
                $variables['attributes']->addClass(['btn', 'btn-' . $class]);
              }
            }
            break;

          case 'contains':
            if (strpos(mb_strtolower($string), mb_strtolower($text)) !== FALSE) {
              if (!$variables['attributes']->hasClass('btn-' . $class)) {
                $variables['attributes']->addClass(['btn', 'btn-' . $class]);
              }
            }
            break;
        }
      }
@@ -265,7 +274,6 @@ function belgrade_theme_suggestions_container_alter(array &$suggestions, array $
  }

  return $suggestions;

}
/**
 * Implements hook_theme_suggestions_fieldset().