You are here

function panels_renderer_editor::ajax_style_type in Panels 6.3

Same name and namespace in other branches
  1. 7.3 plugins/display_renderers/panels_renderer_editor.class.php \panels_renderer_editor::ajax_style_type()

AJAX entry point to select the style for a display, region or pane.

Parameters

string $type: Either display, region or pane

$pid: The pane id, if a pane. The region id, if a region.

File

plugins/display_renderers/panels_renderer_editor.class.php, line 966
Class file to control the main Panels editor.

Class

panels_renderer_editor
@file Class file to control the main Panels editor.

Code

function ajax_style_type($type, $pid = NULL) {

  // This lets us choose whether we're doing the display's cache or
  // a pane's.
  switch ($type) {
    case 'display':
      $style = isset($this->display->panel_settings['style']) ? $this->display->panel_settings['style'] : 'default';
      $title = t('Default style for this display');
      break;
    case 'region':
      $style = isset($this->display->panel_settings[$pid]['style']) ? $this->display->panel_settings[$pid]['style'] : '-1';

      // -1 signifies to use the default setting.
      $title = t('Panel style for region "!region"', array(
        '!region' => $this->plugins['layout']['panels'][$pid],
      ));
      break;
    case 'pane':
      ctools_include('content');
      $pane =& $this->display->content[$pid];
      $style = isset($pane->style['style']) ? $pane->style['style'] : 'default';
      $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);
      $title = t('Pane style for "!pane"', array(
        '!pane' => $subtype['title'],
      ));
      break;
    default:
      ctools_modal_render(t('Error'), t('Invalid pane id.'));
  }
  $info = $this
    ->get_style($type, $pid);
  $style_plugin = $info[0];
  $style_settings = $info[1];

  // Backward compatibility: Translate old-style stylizer to new style
  // stylizer.
  if ($style == 'stylizer' && !empty($style_settings['style']) && $style_settings['style'] != '$') {
    $style = 'stylizer:' . $style_settings['style'];
  }
  $form_state = array(
    'display' => &$this->display,
    'style' => $style,
    'title' => $title,
    'ajax' => TRUE,
    'type' => $type,
  );
  $output = ctools_modal_form_wrapper('panels_edit_style_type_form', $form_state);
  if (!empty($output)) {
    $this->commands = $output;
    return;
  }

  // Preserve this; this way we don't actually change the method until they
  // have saved the form.
  $style = panels_get_style($form_state['style']);
  $function = panels_plugin_get_function('styles', $style, $type == 'pane' ? 'pane settings form' : 'settings form');
  if (!$function) {
    if (isset($this->cache->style)) {
      unset($this->cache->style);
    }

    // If there's no settings form, just change the style and exit.
    switch ($type) {
      case 'display':
        $this->display->panel_settings['style'] = $form_state['style'];
        if (isset($this->display->panel_settings['style_settings']['default'])) {
          unset($this->display->panel_settings['style_settings']['default']);
        }
        break;
      case 'region':
        $this->display->panel_settings[$pid]['style'] = $form_state['style'];
        if (isset($this->display->panel_settings['style_settings'][$pid])) {
          unset($this->display->panel_settings['style_settings'][$pid]);
        }
        break;
      case 'pane':
        $pane->style['style'] = $form_state['style'];
        if (isset($pane->style['settings'])) {
          unset($pane->style['settings']);
        }
        break;
    }
    panels_edit_cache_set($this->cache);
    $this->commands[] = ctools_modal_command_dismiss();
    if ($type == 'pane') {
      $this
        ->command_update_pane($pane);
    }
    else {
      if ($type == 'region') {
        $this
          ->command_update_region_links($pid);
      }
      else {
        $this
          ->command_update_display_links();
      }
    }
  }
  else {
    if ($form_state['style'] != $form_state['old_style']) {
      $this->cache->style = $form_state['style'];
      panels_edit_cache_set($this->cache);
    }

    // send them to next form.
    return $this
      ->ajax_style_settings($type, $pid);
  }
}