<?php

/**
 * @file
 * Functions to support theming form layout in the Toc Master theme.
 */

use Drupal\Core\Render\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Html;

/**
 * Implements hook_preprocess_form_element__checkbox().
 */
function toc_lnr_preprocess_form_element__checkbox(&$vars) {
  _toc_lnr_preprocess_checkbox_styled_tag($vars);
}

/**
 * Helper for above. Allows us to change images a bit easier in custom forms.
 */
function _toc_lnr_preprocess_checkbox_styled_tag(&$vars, string $image_field = 'field_term_image', string $style_id = 'medium') {
  $element = $vars['element'];
  if (!empty($element['#toc_master_styled_filters'])) {
    $style = $element['#toc_master_styled_filters'];
    // Button groups.
    if ($style == 'button_group_hoz') {
      $vars["label"]['#title'] = str_replace('btn-default', 'btn-dark', $vars["label"]['#title']);
    }
    if ($style == 'button_group_vert') {
      $vars["label"]['#title'] = str_replace('btn-default', 'btn-dark', $vars["label"]['#title']);
    }
  }
}
