Project

General

Profile

Download (3.12 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * Implementation of hook_panels_layouts()
5
 */
6
// Plugin definition
7
$plugin = array(
8
  'title'       => t('No wrapper'),
9
  'category'    => t('Columns: 1'),
10
  'icon'        => 'icon.png',
11

    
12
  'theme'       => 'zen_no_wrapper',
13

    
14
  'regions'     => array(
15
    'main'      => t('Main'),
16
  ),
17

    
18
  'settings form'     => 'zen_no_wrapper_settings_form',
19
  'settings validate' => 'zen_no_wrapper_settings_validate',
20
  'settings submit'   => 'zen_no_wrapper_settings_submit',
21
);
22

    
23
/**
24
 * Form for layout settings.
25
 */
26
function zen_no_wrapper_settings_form(&$display, $layout, $settings) {
27
  $form = array();
28

    
29
  $form['layout_settings'] = array(
30
    '#type' => 'fieldset',
31
    '#title' => t('Layout settings'),
32
    '#description' => t('Note: if this setting is used, a wrapper div will be added to accomodate the needed classes.'),
33
    '#collapsible' => TRUE,
34
    '#collapsed' => TRUE,
35
  );
36

    
37
  // Create a classes text field for each region in the layout.
38
  foreach ($layout['regions'] as $region => $label) {
39
    $form['layout_settings'][$region . '_classes'] = array(
40
      '#type' => 'textfield',
41
      '#title' => t('Classes for the “@region” region', array('@region' => $label)),
42
      '#default_value' => isset($settings[$region . '_classes']) ? $settings[$region . '_classes'] : '',
43
      '#description' => t('CSS class (or classes) to apply to the @region region in the layout. This may be blank.', array('@region' => $label)),
44
    );
45
  }
46

    
47
  return $form;
48
}
49

    
50
/**
51
 * Form validation for layout settings.
52
 */
53
function zen_no_wrapper_settings_validate(&$form_state, $form, &$display, $layout, $settings) {
54
  // Since we allow underscores, change the css filter from Drupal's default.
55
  $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '');
56
  foreach (array_keys($layout['regions']) as $region) {
57
    // Ensure that each class is valid.
58
    foreach (explode(' ', $form_state['layout_settings'][$region . '_classes']) as $class) {
59
      $cleaned_class = drupal_clean_css_identifier($class, $filter);
60
      // CSS identifiers can't start with a number or a dash and a number.
61
      $cleaned_class = preg_replace('/^\-?\d+/', '', $cleaned_class);
62
      if ($class != $cleaned_class) {
63
        form_set_error($region . '_classes', t('The class "@class" is invalid. Here’s an alternative class name that is valid: @alternate', array('@class' => $class, '@alternate' => $cleaned_class)));
64
      }
65
    }
66
  }
67
}
68

    
69
/**
70
 * Form submit handler for layout settings.
71
 */
72
function zen_no_wrapper_settings_submit(&$form_state, &$display, $layout, $settings) {
73
  // Move the settings out of the 'layout_settings' array.
74
  foreach (array_keys($form_state['layout_settings']) as $key) {
75
    $form_state[$key] = $form_state['layout_settings'][$key];
76
  }
77
  unset($form_state['layout_settings']);
78
}
79

    
80
/**
81
 * Implements hook_preprocess_HOOK().
82
 */
83
function template_preprocess_zen_no_wrapper(&$variables, $hook) {
84
  foreach (array_keys($variables['layout']['regions']) as $region) {
85
    // Pull out the region classes to easy-to-handle variables.
86
    $variables[$region . '_classes'] = !empty($variables['settings'][$region . '_classes']) ? ' ' . $variables['settings'][$region . '_classes'] : '';
87
  }
88
}
(3-3/3)