Projet

Général

Profil

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

root / drupal7 / sites / all / modules / panels / includes / add-content.inc @ 136a805a

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains template preprocess files for the add content modal themes.
6
 */
7

    
8
/**
9
 * Preprocess the primary entry level theme.
10
 */
11
function template_preprocess_panels_add_content_modal(&$vars) {
12
  $vars['categories_array'] = array();
13

    
14
  // Process the list of categories.
15
  foreach ($vars['categories'] as $key => $category_info) {
16
    // 'root' category is actually displayed under the categories, so
17
    // skip it.
18
    if ($key == 'root') {
19
      continue;
20
    }
21

    
22
    $class = 'panels-modal-add-category';
23
    if ($key == $vars['category']) {
24
      $class .= ' active';
25
    }
26

    
27
    $url = $vars['renderer']->get_url('select-content', $vars['region'], $key);
28
    $vars['categories_array'][] = ctools_ajax_text_button($category_info['title'], $url, '', $class);
29
  }
30

    
31
  // Now render the top level buttons (aka the root category) if any.
32
  $vars['root_content'] = '';
33
  if (!empty($vars['categories']['root'])) {
34
    foreach ($vars['categories']['root']['content'] as $content_type) {
35
      $vars['root_content'] .= theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content_type));
36
    }
37
  }
38
}
39

    
40
/**
41
 * Process the panels add content modal.
42
 *
43
 * This is run here so that preprocess can make changes before links are
44
 * actually rendered.
45
 */
46
function template_process_panels_add_content_modal(&$vars) {
47
  $content = !empty($vars['categories'][$vars['category']]['content']) ? $vars['categories'][$vars['category']]['content'] : array();
48

    
49
  // If no category is selected or the category is empty or our special empty
50
  // category render a 'header' that will appear instead of the columns.
51
  if (empty($vars['category']) || empty($content) || $vars['category'] == 'root') {
52
    $vars['header'] = t('Content options are divided by category. Please select a category from the left to proceed.');
53
  }
54
  else {
55
    $titles = array_keys($content);
56
    natcasesort($titles);
57

    
58
    // This will default to 2 columns in the theme definition but could be
59
    // changed by a preprocess. Ensure there is at least one column.
60
    $columns = max(1, $vars['column_count']);
61
    $vars['columns'] = array_fill(1, $columns, '');
62

    
63
    $col_size = count($titles) / $columns;
64
    $count = 0;
65
    foreach ($titles as $title) {
66
      $which = floor($count++ / $col_size) + 1;
67
      $vars['columns'][$which] .= theme('panels_add_content_link', array('renderer' => $vars['renderer'], 'region' => $vars['region'], 'content_type' => $content[$title]));
68
    }
69
  }
70

    
71
  $vars['messages'] = theme('status_messages');
72
}
73

    
74
/**
75
 * Preprocess the add content link used in the modal.
76
 */
77
function template_preprocess_panels_add_content_link(&$vars) {
78
  $vars['title'] = filter_xss_admin($vars['content_type']['title']);
79
  $vars['description'] = isset($vars['content_type']['description']) ? $vars['content_type']['description'] : $vars['title'];
80
  $vars['icon'] = ctools_content_admin_icon($vars['content_type']);
81
  $vars['url'] = $vars['renderer']->get_url('add-pane', $vars['region'], $vars['content_type']['type_name'], $vars['content_type']['subtype_name']);
82
  $subtype_class = 'add-content-link-' . str_replace('_', '-', $vars['content_type']['subtype_name']);
83
  $vars['image_button'] = ctools_ajax_image_button($vars['icon'], $vars['url'], $vars['description'], $subtype_class . '-image-button panels-modal-add-config');
84
  $vars['text_button'] = ctools_ajax_text_button($vars['title'], $vars['url'], $vars['description'], $subtype_class . '-text-button panels-modal-add-config');
85
  if (function_exists('ctools_ajax_icon_text_button')) {
86
    $vars['icon_text_button'] = ctools_ajax_icon_text_button($vars['title'], $vars['icon'], $vars['url'], $vars['description'], $subtype_class . '-icon-text-button panels-modal-add-config');
87
  }
88
}