You are here

function socialbase_preprocess_input in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  2. 8 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  3. 8.2 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  4. 8.3 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  5. 8.4 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  6. 8.6 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  7. 8.7 themes/socialbase/includes/input.inc \socialbase_preprocess_input()
  8. 8.8 themes/socialbase/includes/input.inc \socialbase_preprocess_input()

Implements hook_preprocess_input().

File

themes/socialbase/includes/input.inc, line 11
The input inc file for the Social base theme.

Code

function socialbase_preprocess_input(&$variables) {
  if (isset($variables['element']['#type']) && $variables['element']['#type'] === 'radio') {

    // Only reaction on the visibility field.
    if (strpos($variables['element']['#id'], 'field-visibility') !== FALSE) {
      $title = $variables['element']['#title'];
      $variables['selected_material_icon'] = _socialbase_get_visibility_icon($title);
      if (isset($variables['element']['#return_value']) && isset($variables['element']['#default_value'])) {
        if ($variables['element']['#return_value'] === $variables['element']['#default_value']) {
          $variables['element']['active'] = 'active';
          $variables['active'] = 'active';
        }
      }
    }
  }

  // Set "add more managers" button style.
  if (isset($variables['element']['#array_parents']) && in_array('add_more', $variables['element']['#array_parents'], TRUE) && $variables['type'] == 'submit') {
    $variables['button_type'] = 'flat';
  }
  if (isset($variables['element']['#array_parents'])) {
    if (in_array('save_modal', $variables['element']['#array_parents'], TRUE)) {
      $variables['button_type'] = 'primary';
    }
  }

  // For all buttons in file upload set type to flat,
  // usually tables -> remove button.
  if (isset($variables['element']['#submit']) && in_array('file_managed_file_submit', $variables['element']['#submit'], TRUE)) {
    $variables['button_type'] = 'flat';
  }
  if (isset($variables['element']['#addsearchicon'])) {
    $variables['addsearchicon'] = TRUE;
  }

  // Button types are determined in the hook_form_alter and set to be
  // forced here again so the twig fill can use the variable params:
  // ['#button_type']
  // ['#button_level'].
  if (isset($variables['element']['#button_type'])) {
    if ($variables['element']['#button_type'] == 'primary') {
      $variables['button_type'] = 'primary';
    }
    if ($variables['element']['#button_type'] == 'danger' || $variables['element']['#button_type'] == 'default') {
      $variables['button_type'] = 'default';
    }
    if ($variables['element']['#button_type'] == 'flat') {
      $variables['button_type'] = 'flat';
    }
    if ($variables['element']['#button_type'] == 'accent') {
      $variables['button_type'] = 'accent';
    }
  }
  if (isset($variables['element']['#button_size'])) {
    if ($variables['element']['#button_size'] == 'small') {
      $variables['button_size'] = 'small';
    }
  }

  // If a split button doesn't have a button_type variable,
  // set it to default (fallback).
  if (isset($variables['element']['#split']) && !isset($variables['element']['#button_type'])) {
    $variables['button_type'] = 'default';
  }
  if (isset($variables['element']['#button_level'])) {
    if ($variables['element']['#button_level'] == 'raised') {
      $variables['button_level'] = 'raised';
    }
  }

  // Make sure we can use a span class caret in the button.
  if (!empty($variables['element']['#attributes']['data-caret']) && $variables['element']['#attributes']['data-caret'] === 'true') {
    $variables['element']['caret'] = [
      '#markup' => '<span class="caret"></span>',
    ];
  }

  // Render a simple VBO checkbox.
  if (isset($variables['element']['#id']) && $variables['element']['#id'] !== NULL && (strpos($variables['element']['#id'], 'edit-views-bulk-operations') !== FALSE || strpos($variables['element']['#id'], 'edit-social-views-bulk-operations') !== FALSE) && $variables['type'] == 'checkbox') {
    $variables['element']['#simple_checkbox'] = TRUE;
    $variables['simple_checkbox'] = TRUE;
  }
}