You are here

function styles_ui_style_edit_form_submit in Styles 7.2

Submission handler for the add style form.

File

contrib/styles_ui/styles_ui.admin.inc, line 271
Administrative page callbacks for the Styles UI module.

Code

function styles_ui_style_edit_form_submit(&$form, &$form_state) {
  $field_type = $form_state['values']['field_type'];
  $style_name = $form_state['values']['name'];
  $style = array(
    'field_type' => $field_type,
    'name' => $style_name,
    'description' => $form_state['values']['description'],
  );

  // Save the new style.
  styles_style_save($style);

  // Get the containers for this field type.
  $styles = styles_default_presets($field_type);
  $containers = styles_default_containers($field_type);
  foreach ($form_state['values']['containers'] as $container_name => $container) {
    if (is_array($container)) {
      $default_preset = isset($styles['containers'][$container_name]['styles'][$style_name]['default preset']) ? $styles['containers'][$container_name]['styles'][$style_name]['default preset'] : $styles['containers'][$container_name]['default preset'];
      $delete_only = $default_preset == $container['preset'];
      styles_style_save_preset($field_type, $container_name, $style_name, $container['preset'], $delete_only);
    }
  }

  // Redirect to this style's edit page.
  $form_state['redirect'] = $containers['admin']['path'] . '/edit/' . $style_name;
}