You are here

function skinr_submit_handler in Skinr 6.2

Same name and namespace in other branches
  1. 6 includes/handlers.inc \skinr_submit_handler()

Skinr submit handler.

Parameters

&$form: Passes in the $form parameter from hook_form_submit().

$form_state: Passes in the $form_state parameter from hook_form_submit().

$module: The module that is currently being processed.

$form_settings: The settings from hook_skinr_config() for the form that's currently being processed.

Return value

TRUE if we get access, FALSE if we don't.

1 string reference to 'skinr_submit_handler'
_skinr_fetch_config_defaults in ./skinr.module
Fetch default configuration data for modules.

File

./skinr.handlers.inc, line 104
Defines the various handler objects to support Skinr.

Code

function skinr_submit_handler(&$form, $form_state, $module, $form_settings) {
  if (isset($form_state['values']['skinr_settings'][$module . '_group'])) {
    foreach ($form_state['values']['skinr_settings'][$module . '_group'] as $theme_name => $theme) {
      if (!empty($theme['widgets']) && is_array($theme['widgets']) || isset($theme['_additional'])) {
        $skinr = new stdClass();
        $skinr->theme = $theme_name;
        $skinr->module = $module;
        $skinr->sid = skinr_handler('form_index_handler', 'submit', $form_settings['index_handler'], $form, $form_state);
        $skinr->skins = array();
        $saved = skinr_get($skinr->theme, $skinr->module, $skinr->sid);
        if (!empty($theme['widgets']) && is_array($theme['widgets'])) {
          foreach ($theme['widgets'] as $skin_id => $skin_value) {
            $skinr->skins[$skin_id] = $skin_value;
          }
        }
        if (isset($theme['_additional'])) {
          $theme['_additional'] = trim($theme['_additional']);
          if (!empty($theme['_additional'])) {
            $skinr->skins['_additional'] = $theme['_additional'];
          }
        }
        else {
          if (!user_access('access skinr classes') && isset($saved->skins['_additional'])) {

            // The user didn't have access to change this. Ensure the existing
            // custom classes remain by populating the element with the
            // previously saved values.
            $value->skins['_additional'] = $saved->skins['_additional'];
          }
        }
        if (isset($theme['_template'])) {
          $theme['_template'] = trim($theme['_template']);
          if (!empty($theme['_template'])) {
            $skinr->skins['_template'] = $theme['_template'];
          }
        }
        else {
          if (!user_access('access skinr classes') && isset($saved->skins['_template'])) {

            // The user didn't have access to change this. Ensure the existing
            // template selection remains by populating the element with the
            // previously saved values.
            $value->skins['_template'] = $saved->skins['_template'];
          }
        }
        if (empty($skinr->sid)) {

          // We didn't receive a valid sid, so raise an error
          drupal_set_message(t("Skinr settings weren't saved due to an error."), 'error');
        }
        skinr_set($skinr);
      }
    }
  }
}