You are here

function panels_skinr_submit_handler_settings in Skinr 6.2

Same name and namespace in other branches
  1. 6 modules/panels.skinr.inc \panels_skinr_submit_handler_settings()

Skinr submit handler.

Parameters

$op: What kind of action is being performed. Possible values:

  • "access skinr": access to edit skinr's selector
  • "access skinr classes": access to edit skinr's additional classes

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

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

Return value

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

Related topics

1 string reference to 'panels_skinr_submit_handler_settings'
panels_skinr_config in modules/panels.skinr.inc
Implementation of hook_skinr_config().

File

modules/panels.skinr.inc, line 214
Provide skinr handling for panels.module.

Code

function panels_skinr_submit_handler_settings(&$form, $form_state, $module, $form_settings) {
  foreach ($form_state['values']['skinr_settings'][$module . '_group'] as $theme_name => $theme) {
    if (!empty($theme['widgets']) && is_array($theme['widgets']) || isset($theme['_additional'])) {
      $hook = $module;
      $sid = skinr_handler('form_index_handler', 'submit', $form_settings['index_handler'], $form, $form_state);
      $saved = skinr_get($skinr->theme, $skinr->module, $skinr->sid);

      // Key doesn't exist properly for new displays. Perhaps we should inject a timestamp based key into the display object
      // and use that for reference on the final submit? If it works...
      $value = array();
      if (!empty($theme['widgets']) && is_array($theme['widgets'])) {
        foreach ($theme['widgets'] as $skin_id => $skin_value) {
          $value[$skin_id] = $skin_value;
        }
      }
      if (isset($theme['_additional'])) {
        $theme['_additional'] = trim($theme['_additional']);
        if (!empty($theme['_additional'])) {
          $value['_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['_additional'] = $saved->skins['_additional'];
        }
      }
      if (isset($theme['_template'])) {
        $theme['_template'] = trim($theme['_template']);
        if (!empty($theme['_template'])) {
          $value['_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['_template'] = $saved->skins['_template'];
        }
      }
      if (empty($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');
      }

      // Save skinr_settings for this panel display in cache.
      ctools_include('object-cache');
      if (!($skinr_data = ctools_object_cache_get('skinr', $form_state['display']->did, TRUE))) {
        $skinr_data = array();

        // Fetch skinr data.
        $skinr = skinr_get($theme_name);
        if (isset($skinr[$module])) {
          foreach ($skinr[$module] as $skinr_key => $skinr_value) {
            if (drupal_substr($skinr_key, 0, drupal_strlen('display-' . $form_state['display']->did)) == 'display-' . $form_state['display']->did) {
              $skinr_data[$theme_name][$skinr_key] = $skinr_value;
            }
          }
        }
      }
      $skinr_data[$theme_name][$sid] = $value;
      ctools_object_cache_set('skinr', $form_state['display']->did, $skinr_data);
    }
  }
}