You are here

function _classy_panel_styles_apply in Classy Panel Styles 7

Adds Classy Panel Styles to the Drupal.settings javascript object.

Parameters

string $type: One of 'pane' or 'region'.

mixed $item_id: Pane ID (int) or Region ID (string).

string $style: The name of the currently selected style.

array $conf: The associative array of style settings.

2 calls to _classy_panel_styles_apply()
_classy_panel_styles_apply_all in ./classy_panel_styles.module
Applies Classy Panel Styles to backend Panels pages via Javascript.
_classy_panel_styles_preprocess in plugins/styles/classy_panel_styles/classy_panel_styles.inc
Adds CSS to response; Adds classes to the template variable or JS settings.

File

./classy_panel_styles.module, line 234
Module file for Classy Panel Styles.

Code

function _classy_panel_styles_apply($type, $item_id, $style = NULL, array $conf = array(), $renderer_class = 'panels_renderer_editor') {

  // Calculate the HTML id of the region/pane div in the markup.
  switch ($type) {
    case 'pane':
      switch ($renderer_class) {

        // Standard editor.
        case 'panels_renderer_editor':
          $id = 'panel-pane-' . $item_id;
          break 2;

        // IPE.
        case 'panels_renderer_ipe':
          $id = 'panels-ipe-paneid-' . $item_id;
          break 2;
        default:

          // If neither IPE nor standard editor, do nothing.
          return;
      }
    case 'region':
      switch ($renderer_class) {

        // Standard editor.
        case 'panels_renderer_editor':
          $id = 'panel-region-' . $item_id;
          break 2;

        // IPE.
        case 'panels_renderer_ipe':
          $id = 'panels-ipe-regionid-' . $item_id;
          break 2;
        default:

          // If neither IPE nor standard editor, do nothing.
          return;
      }
    default:

      // If not a pane or region, don't do anything.
      return;
  }

  // Get the array of classes to add. If not using classy_panel_styles, send an
  // empty array to clear any previously applied classy_panel_styles classes.
  $classes = _classy_panel_styles_is($style) ? _classy_panel_styles_filter_conf($conf) : array();

  // Add to the Drupal.settings object. Note that subsequent (ajax) calls have
  // some wonky behavior... When adding a value for an existing element, it
  // neither replaces nor merges: Your element will turn into an array with
  // two subelements, both of which have the new value. And no matter how many
  // times you call it, the element always has exactly two subelements.
  drupal_add_js(array(
    'classyPanels' => array(
      $id => implode(' ', $classes),
    ),
  ), 'setting');
}