You are here

function panels_stylizer_pane_add_style in Panels 7.3

Same name and namespace in other branches
  1. 6.3 plugins/styles/stylizer.inc \panels_stylizer_pane_add_style()

Allow on-the-fly creation of styles in panes.

1 call to panels_stylizer_pane_add_style()
panels_stylizer_stylizer_style_settings_form in plugins/styles/stylizer.inc
Settings form callback.
1 string reference to 'panels_stylizer_pane_add_style'
stylizer.inc in plugins/styles/stylizer.inc

File

plugins/styles/stylizer.inc, line 196

Code

function panels_stylizer_pane_add_style(&$renderer, $plugin, &$conf, $type, $pid, $step = NULL) {
  if (!user_access("administer panels {$type} styles")) {
    return;
  }

  // Reset the $_POST['ajax_html_ids'] values to preserve
  // proper IDs on form elements when auto-submit is used.
  $_POST['ajax_html_ids'] = array();
  ctools_include('stylizer');
  $js = FALSE;
  $path = $renderer
    ->get_url('style', 'custom', $type, $pid, '%step');
  $info = array(
    'module' => 'panels',
    'type' => $type,
    'path' => $path,
    'modal' => t('Create custom style'),
    'owner form' => 'panels_stylizer_edit_pane_style_form',
    'owner form validate' => 'panels_stylizer_edit_pane_style_form_validate',
    'owner form submit' => 'panels_stylizer_edit_pane_style_form_submit',
    'owner settings' => array(
      'preconfigured' => FALSE,
      'name' => '',
      'admin_title' => '',
      'admin_description' => '',
    ),
    'cache' => &$renderer->cache,
    'conf' => &$conf,
    'pid' => $pid,
  );
  if (!empty($conf['settings'])) {
    $info['settings'] = $conf['settings'];
  }
  $output = ctools_stylizer_edit_style($info, TRUE, $step);
  if (!empty($info['complete'])) {
    if (!empty($info['owner settings']['preconfigured'])) {
      ctools_include('export');
      $style = ctools_export_crud_new('stylizer');
      $style->name = $info['settings']['name'];
      $style->admin_title = $info['owner settings']['admin_title'];
      $style->admin_description = $info['owner settings']['admin_description'];
      $style->settings = $info['settings'];
      ctools_export_crud_save('stylizer', $style);
      $conf['style'] = $info['settings']['name'];
      if (isset($conf['settings'])) {
        unset($conf['settings']);
      }
    }
    else {
      $conf['style'] = '$';
      $conf['settings'] = $info['settings'];
    }

    // Be sure to unset the temporary if the style was just changed.
    if (isset($renderer->cache->style)) {
      unset($renderer->cache->style);
    }

    // $conf was a reference so it should just modify.
    panels_edit_cache_set($renderer->cache);
    $renderer->commands[] = ctools_modal_command_dismiss();
    if ($type == 'pane') {
      $renderer
        ->command_update_pane($pid);
    }
    elseif ($type == 'region') {
      $renderer
        ->command_update_region_links($pid);
    }
    else {
      $renderer
        ->command_update_display_links();
    }
  }
  else {
    $renderer->commands = $output;
  }
}