You are here

function skinr_ui_form_submit in Skinr 7.2

Same name and namespace in other branches
  1. 6.2 skinr_ui.module \skinr_ui_form_submit()

Form submission handler for skinr_ui_form_alter().

2 string references to 'skinr_ui_form_submit'
skinr_context_ui_form_skinr_ui_form_alter in skinr_context/skinr_context_ui.module
Implements hook_form_alter().
skinr_ui_form in ./skinr_ui.edit.inc
Form builder for the skins configuration form.

File

./skinr_ui.edit.inc, line 340
Page callbacks for the Skinr UI module related to editing skins.

Code

function skinr_ui_form_submit($form, &$form_state) {
  $current_theme = skinr_current_theme(TRUE);
  $module = $form_state['values']['module'];
  $element = $form_state['values']['element'];
  if (!empty($form_state['values']['skinr_settings'])) {
    foreach ($form_state['values']['skinr_settings'] as $theme_name => $theme) {

      // Process widgets.
      if (!empty($theme) && is_array($theme)) {
        foreach ($theme as $skin_name => $options) {
          if ($skin_name == '_additional' && !user_access('edit advanced skin settings')) {

            // This user doesn't have access to alter these options.
            continue;
          }

          // Ensure options is an array.
          if (!is_array($options)) {
            $options = $skin_name == '_additional' ? explode(' ', $options) : array(
              $options,
            );
          }

          // Sanitize options.
          $options = _skinr_array_strip_empty($options);

          // Find existing skin.
          $params = array(
            'theme' => $theme_name,
            'module' => $module,
            'element' => $element,
            'skin' => $skin_name,
          );
          $sids = skinr_skin_get_sids($params);
          unset($skin);
          if (!empty($sids)) {
            $sid = reset($sids);
            $skin = skinr_skin_load($sid);
          }
          if (empty($options)) {
            if (!empty($skin)) {

              // Delete this skin configuration.
              skinr_skin_delete($skin->sid);
            }
            continue;
          }
          if (empty($skin)) {

            // It doesn't exist, so create a new skin.
            $skin = new stdClass();
            $skin->theme = $theme_name;
            $skin->module = $module;
            $skin->element = $element;
            $skin->skin = $skin_name;
          }
          $skin->options = $options;
          $skin->status = 1;

          // Save skin.
          if (!skinr_skin_save($skin)) {
            drupal_set_message(t("Skinr settings for %skin weren't saved due to an error.", array(
              '%skin' => $skin_name,
            )), 'error');
          }
        }
      }
    }
  }
}