You are here

function block_class_styles_admin_settings_validate in Block Class Styles 7.2

Same name and namespace in other branches
  1. 7 block_class_styles.admin.inc \block_class_styles_admin_settings_validate()

Form validation handler for block_class_styles_admin_settings_validate().

Related topics

1 string reference to 'block_class_styles_admin_settings_validate'
block_class_styles_admin_settings in ./block_class_styles.admin.inc
Form builder. Configure my_module.

File

./block_class_styles.admin.inc, line 183
Administration page callbacks for the block_class_styles module.

Code

function block_class_styles_admin_settings_validate($form, &$form_state) {
  $presets =& $form_state['values']['block_class_styles_presets'];
  $hidden =& $form_state['values']['block_class_styles_hidden'];

  // Invert our selection because active looks better in the UI, but hidden
  // stores with less memory.
  $hidden = array_diff_key(block_class_styles_info(TRUE), array_filter($hidden));
  $temp = explode("\n", trim($presets));
  if (empty($temp) || empty($temp[0])) {
    $presets = NULL;
    return;
  }
  $temp3 = array();
  foreach ($temp as $value) {
    if (!strstr($value, '|')) {
      form_set_error('block_class_styles_presets', t('Separate class and Style Name with a pipe |'));
    }
    else {
      $temp2 = explode('|', trim($value));
      $temp3[$temp2[0]] = $temp2[1];
    }
  }
  $presets = $temp3;
  $new_presets = array_flip($presets);
  $old_presets = array_flip(block_class_styles_info());
  $diff = array_diff($old_presets, $new_presets);
  foreach (array_keys($diff) as $style) {
    if (!array_key_exists($style, $new_presets)) {
      form_set_error('block_class_styles_presets', t('You <b>cannot change both style name and css definition at the same time</b>.  This must be done in two saves. To delete a style, use the checkboxes below the Style Definitions.'));
    }
    else {

      // The admin has changed a css class and we need to update the database
      // directly.
      db_update(_block_class_tablename())
        ->fields(array(
        'css_class' => $new_presets[$style],
      ))
        ->condition('css_class', $old_presets[$style])
        ->execute();
    }
  }
}