You are here

function styleguide_palette_form_submit in Style Guide 7

Form submission handler for styleguide_palette_form().

See also

styleguide_palette_form_validate()

File

styleguide_palette/styleguide_palette.admin.inc, line 155
Administrative page callbacks for the Style Guide Swatch module.

Code

function styleguide_palette_form_submit($form, &$form_state) {
  $form_state['values'] += array(
    'palette' => array(),
  );
  foreach ($form_state['values']['palette'] as $name => $swatch) {
    $swatch['name'] = $name;
    drupal_write_record('styleguide_palette_swatch', $swatch, 'id');
  }
  $new_swatch = array_intersect_key(array_filter($form_state['values']), array_flip(array(
    'name',
    'description',
    'hex',
    'theme',
  )));

  // The 'theme' key will always be present, so ensure that a new swatch was
  // actually added.
  $swatch_updated = array_intersect_key($new_swatch, array_flip(array(
    'name',
    'hex',
  )));
  if (!empty($swatch_updated)) {
    drupal_write_record('styleguide_palette_swatch', $new_swatch);
    drupal_set_message(t('Style guide swatches added.'));
  }
  elseif (!empty($form_state['values']['palette'])) {
    drupal_set_message(t('Style guide palette updated.'));
  }
}