You are here

function fusion_apply_submit_handler in Fusion Accelerator 7

Same name and namespace in other branches
  1. 7.2 fusion_apply/fusion_apply.handlers.inc \fusion_apply_submit_handler()

Fusion Apply 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_fusion_apply_config() for the form that's currently being processed.

1 string reference to 'fusion_apply_submit_handler'
fusion_apply_config_info_default in fusion_apply/fusion_apply.module
Prepare default configuration data for modules.

File

fusion_apply/fusion_apply.handlers.inc, line 113
Defines the various default handler functions to support Fusion Apply.

Code

function fusion_apply_submit_handler(&$form, $form_state, $module, $form_settings) {
  if (!($element = fusion_apply_handler('form_index_handler', 'submit', $form_settings['index_handler'], $form, $form_state))) {

    // We require a valid element to continue.
    // @todo This should really be in a validation handler.
    drupal_set_message(t("Skin settings weren't saved due to an error."), 'error');
    return;
  }
  if (isset($form_state['values']['fusion_apply_settings'][$module . '_group'])) {
    foreach ($form_state['values']['fusion_apply_settings'][$module . '_group'] as $theme_name => $theme) {

      // Process widgets.
      if (!empty($theme['groups']) && is_array($theme['groups'])) {
        foreach ($theme['groups'] 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;
          }

          // Convert manually entered classes into an array.
          if ($skin_name == '_additional') {
            $options = explode(' ', $options['_additional']);
          }
          elseif (!is_array($options)) {
            $options = array(
              $options,
            );
          }

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

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

              // Delete this skin configuration.
              fusion_apply_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 (!fusion_apply_skin_save($skin)) {
            drupal_set_message(t("Fusion settings for %skin weren't saved due to an error.", array(
              '%skin' => $skin_name,
            )), 'error');
          }
        }
      }
    }
  }
}