You are here

function block_class_styles_admin_settings_validate in Block Class Styles 7

Same name and namespace in other branches
  1. 7.2 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 129
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'];
  $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());
  $delete = drupal_map_assoc(array_filter($form_state['values']['block_class_styles_delete']));
  $diff = array_diff($old_presets, $new_presets, $delete);
  foreach ($diff as $style => $css) {
    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 {
      db_update('block_class')
        ->fields(array(
        'css_class' => $new_presets[$style],
      ))
        ->condition('css_class', $css)
        ->execute();
    }
  }
  $presets = array_diff_key($presets, $delete);
}