Projet

Général

Profil

Paste
Télécharger (7,81 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / panels_ipe / panels_ipe.module @ 5a7e6170

1
<?php
2

    
3
/**
4
 * Implementation of hook_ctools_plugin_directory().
5
 */
6
function panels_ipe_ctools_plugin_directory($module, $plugin) {
7
  if ($module == 'panels' && $plugin == 'display_renderers') {
8
    return 'plugins/' . $plugin;
9
  }
10
}
11

    
12
/**
13
 * Implementation of hook_ctools_plugin_api().
14
 *
15
 * Inform CTools about version information for various plugins implemented by
16
 * Panels.
17
 *
18
 * @param string $owner
19
 *   The system name of the module owning the API about which information is
20
 *   being requested.
21
 * @param string $api
22
 *   The name of the API about which information is being requested.
23
 */
24
function panels_ipe_ctools_plugin_api($owner, $api) {
25
  if ($owner == 'panels' && $api == 'pipelines') {
26
    return array(
27
      'version' => 1,
28
      'path' => drupal_get_path('module', 'panels_ipe') . '/includes',
29
    );
30
  }
31
}
32

    
33
/**
34
 * Implementation of hook_theme().
35
 */
36
function panels_ipe_theme() {
37
  return array(
38
    'panels_ipe_pane_wrapper' => array(
39
      'variables' => array('output' => NULL, 'pane' => NULL, 'display' => NULL, 'renderer' => NULL),
40
    ),
41
    'panels_ipe_region_wrapper' => array(
42
      'variables' => array('output' => NULL, 'region_id' => NULL, 'display' => NULL, 'controls' => NULL, 'renderer' => NULL),
43
    ),
44
    'panels_ipe_add_pane_button' => array(
45
      'variables' => array('region_id' => NULL, 'display' => NULL, 'renderer' => NULL),
46
    ),
47
    'panels_ipe_placeholder_pane' => array(
48
      'variables' => array('region_id' => NULL, 'region_title' => NULL),
49
    ),
50
    'panels_ipe_dnd_form_container' => array(
51
      'variables' => array('link' => NULL, 'cache_key' => NULL, 'display' => NULL),
52
    ),
53
    'panels_ipe_toolbar' => array(
54
      'variables' => array('buttons' => NULL),
55
    ),
56
  );
57
}
58

    
59
/**
60
 * Theme the 'placeholder' pane, which is shown on an active IPE when no panes
61
 * live in that region.
62
 *
63
 * @param string $region_id
64
 * @param string $region_title
65
 */
66
function theme_panels_ipe_placeholder_pane($vars) {
67
  $region_id = $vars['region_id'];
68
  $region_title = $vars['region_title'];
69

    
70
  $output = '<div class="panels-ipe-placeholder-content">';
71
  $output .= "<h3>$region_title</h3>";
72
  $output .= '</div>';
73
  return $output;
74
}
75

    
76
function template_preprocess_panels_ipe_pane_wrapper(&$vars) {
77
  $pane = $vars['pane'];
78
  $display = $vars['display'];
79
  $renderer = $vars['renderer'];
80

    
81
  $content_type = ctools_get_content_type($pane->type);
82
  $subtype = ctools_content_get_subtype($content_type, $pane->subtype);
83
  $vars['links'] = array();
84

    
85
  if (ctools_content_editable($content_type, $subtype, $pane->configuration)) {
86
    $vars['links']['edit'] = array(
87
      'title' => isset($content_type['edit text']) ? '<span>' . $content_type['edit text'] . '</span>' : '<span>' . t('Settings') . '</span>',
88
      'href' => $renderer->get_url('edit-pane', $pane->pid),
89
      'html' => TRUE,
90
      'attributes' => array(
91
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
92
        'title' => isset($content_type['edit text']) ? $content_type['edit text'] : t('Settings'),
93
        // 'id' => "pane-edit-panel-pane-$pane->pid",
94
      ),
95
    );
96
  }
97

    
98
  // Add option to configure style in IPE
99
  if (user_access('administer panels styles')) {
100
    $vars['links']['style'] = array(
101
      'title' => '<span>' . t('Style') . '</span>',
102
      'href' => $renderer->get_url('style-type', 'pane', $pane->pid),
103
      'html' => TRUE,
104
      'attributes' => array(
105
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
106
        'title' => t('Style'),
107
      ),
108
    );
109
  }
110

    
111
  // Deleting is managed entirely in the js; this is just an attachment point
112
  // for it
113
  $vars['links']['delete'] = array(
114
    'title' => '<span>' . t('Delete') . '</span>',
115
    'href' => '#',
116
    'html' => TRUE,
117
    'attributes' => array(
118
      'class' => 'pane-delete',
119
      'id' => "pane-delete-panel-pane-$pane->pid",
120
      'title' => t('Delete'),
121
    ),
122
  );
123

    
124
  $context = array(
125
    'pane' => $pane,
126
    'display' => $display,
127
    'renderer' => $renderer
128
  );
129
  drupal_alter('panels_ipe_pane_links', $vars['links'], $context);
130

    
131
}
132

    
133
function theme_panels_ipe_pane_wrapper($vars) {
134
  $output = $vars['output'];
135
  $pane = $vars['pane'];
136

    
137
  $attributes = array(
138
    'class' => 'panels-ipe-linkbar',
139
  );
140

    
141
  $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
142

    
143
  if (!empty($pane->locks['type']) && $pane->locks['type'] == 'immovable') {
144
    $links = '<div class="panels-ipe-dragbar panels-ipe-nodraghandle clearfix">' . $links . '</div>';
145
  }
146
  else {
147
    $links = '<div class="panels-ipe-dragbar panels-ipe-draghandle clearfix">' . $links . '<span class="panels-ipe-draghandle-icon"><span class="panels-ipe-draghandle-icon-inner"></span></span></div>';
148
  }
149

    
150
  $handlebar = '<div class="panels-ipe-handlebar-wrapper panels-ipe-on">' . $links . '</div>';
151

    
152
  return $handlebar . $output;
153
}
154

    
155
function theme_panels_ipe_region_wrapper($vars) {
156
  return $vars['controls'] . $vars['output'];
157
}
158

    
159
function template_preprocess_panels_ipe_add_pane_button(&$vars) {
160
  $region_id = $vars['region_id'];
161
  $display = $vars['display'];
162
  $renderer = $vars['renderer'];
163
  $vars['links'] = '';
164

    
165
  // Add option to configure style in IPE
166
  if (user_access('administer panels styles')) {
167
    $vars['links']['style'] = array(
168
      'title' => '<span>' . t('Region style') . '</span>',
169
      'href' => $renderer->get_url('style-type', 'region', $region_id),
170
      'html' => TRUE,
171
      'attributes' => array(
172
        'class' => array('ctools-use-modal', 'panels-ipe-hide-bar', 'style'),
173
        'title' => t('Region style'),
174
      ),
175
    );
176
  }
177

    
178
  // Add option to add items in the IPE
179
  $vars['links']['add-pane'] = array(
180
    'title' => '<span>' . t('Add new pane') . '</span>',
181
    'href' => $renderer->get_url('select-content', $region_id),
182
    'attributes' => array(
183
      'class' => array('ctools-use-modal', 'add', 'panels-ipe-hide-bar'),
184
      'title' => t('Add new pane'),
185
    ),
186
    'html' => TRUE,
187
  );
188

    
189
  $context = array(
190
    'region_id' => $region_id,
191
    'display' => $display,
192
    'renderer' => $renderer,
193
  );
194
  drupal_alter('panels_ipe_region_links', $vars['links'], $context);
195

    
196
}
197

    
198
function theme_panels_ipe_add_pane_button($vars) {
199
  $attributes = array(
200
    'class' => array('panels-ipe-linkbar', 'inline'),
201
  );
202

    
203
  $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
204

    
205
  return '<div class="panels-ipe-newblock panels-ipe-on">' . $links . '</div>';
206
}
207

    
208
/**
209
 * @deprecated
210
 */
211
function panels_ipe_get_cache_key($key = NULL) {
212
  return array();
213
}
214

    
215
/**
216
 * Add a button to the IPE toolbar.
217
 */
218
function panels_ipe_toolbar_add_button($cache_key, $id, $button) {
219
  $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
220
  $buttons[$cache_key][$id] = $button;
221
}
222

    
223
/**
224
 * Implementation of hook_footer()
225
 *
226
 * Adds the IPE control container.
227
 *
228
 * @param unknown_type $main
229
 */
230
function panels_ipe_page_alter(&$page) {
231
  $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
232
  if (empty($buttons)) {
233
    return;
234
  }
235

    
236
  $output = theme('panels_ipe_toolbar', array('buttons' => $buttons));
237

    
238
  $page['page_bottom']['panels_ipe'] = array(
239
    '#markup' => $output,
240
  );
241
}
242

    
243
function theme_panels_ipe_toolbar($vars) {
244
  $buttons = $vars['buttons'];
245

    
246
  $output = "<div id='panels-ipe-control-container' class='clearfix'>";
247
  foreach ($buttons as $key => $ipe_buttons) {
248
    $output .= "<div id='panels-ipe-control-$key' class='panels-ipe-control'>";
249

    
250
    // Controls in this container will appear when the IPE is not on.
251
    $output .= '<div class="panels-ipe-button-container clearfix">';
252
    foreach ($ipe_buttons as $button) {
253
      $output .= is_string($button) ? $button : drupal_render($button);
254
    }
255
    $output .= '</div>';
256

    
257
    // Controls in this container will appear when the IPE is on. It is usually
258
    // filled via AJAX.
259
    $output .= '<div class="panels-ipe-form-container clearfix"></div>';
260
    $output .= '</div>';
261
  }
262

    
263
  $output .= "</div>";
264

    
265
  return $output;
266
}