You are here

function beautytips_admin_submit in BeautyTips 7.2

Same name and namespace in other branches
  1. 6.2 beautytips.admin.inc \beautytips_admin_submit()
  2. 6 beautytips.module \beautytips_admin_submit()

Submit function for beautytips settings form

1 string reference to 'beautytips_admin_submit'
beautytips_admin in ./beautytips.admin.inc
Menu callback - beautytips admin settings form

File

./beautytips.admin.inc, line 212
Beautytips settings form and submit action

Code

function beautytips_admin_submit($form, &$form_state) {
  $values = $form_state['values'];
  if (count($values)) {
    $custom_style = [];
    $css_style = [];
    foreach ($values as $option => $value) {
      if (strpos($option, 'bt-options-box-') === 0) {
        $option = str_replace('bt-options-box-', '', $option);
        $custom_style[$option] = $value;
      }
      else {
        if ($option == 'bt-options-cssClass') {
          $option = str_replace('bt-options-', '', $option);
          $custom_style[$option] = $value;
        }
        else {
          if (strpos($option, 'bt-options-css-') === 0) {
            $option = str_replace('bt-options-css-', '', $option);
            if ($value) {
              $css_style[$option] = $value;
            }
          }
        }
      }
    }

    // Store the defaults - they will be passed to javascript
    $style = beautytips_get_style($values['beautytips_default_style']);
    if (count($custom_style)) {
      foreach ($custom_style as $option => $value) {
        if ($option == 'shadow') {
          if ($value != 'default') {
            $style['shadow'] = $value == 'shadow' ? TRUE : FALSE;
          }
        }
        else {
          if (!empty($value) || $value == '0') {
            $style[$option] = is_numeric($value) ? (int) $value : (string) $value;
          }
        }
      }
    }
    if (count($css_style)) {
      foreach ($css_style as $option => $value) {
        if (!empty($value)) {
          $style['cssStyles'][$option] = (string) $value;
        }
      }
      if (!empty($css_style)) {
        $custom_style['cssStyles'] = $css_style;
      }
    }
    variable_set('beautytips_defaults', $style);
    variable_set('beautytips_custom_style', $custom_style);
    variable_set('beautytips_default_style', $values['beautytips_default_style']);
    cache_clear_all('beautytips:beautytips-styles', 'cache');

    // Store array of selectors that bt will be added to on every page
    $selectors = explode(",", $values['beautytips_added_selectors_string']);
    $test = serialize($selectors);
    if (count($selectors)) {
      foreach ($selectors as $key => $selector) {
        $selectors[$key] = trim($selector);
      }
    }
    variable_set('beautytips_added_selectors_array', $selectors);
  }
  if (module_exists('beautytips_ui')) {
    beautytips_ui_admin_submit($form, $form_state);
  }
}