Projet

Général

Profil

Paste
Télécharger (5,08 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / panels_mini / plugins / content_types / panels_mini.inc @ 136a805a

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains the content type plugin for a mini panel. While this does not
6
 * need to be broken out into a .inc file, it's convenient that we do so
7
 * that we don't load code unnecessarily. Plus it demonstrates plugins
8
 * in modules other than Panels itself.
9
 *
10
 */
11

    
12
/**
13
 * Specially named hook. for .inc file. This looks a little silly due to the
14
 * redundancy, but that's really just because the content type shares a
15
 * name with the module.
16
 */
17
function panels_mini_panels_mini_ctools_content_types() {
18
  return array(
19
    'title' => t('Mini panels'),
20
    'content type' => 'panels_mini_panels_mini_content_type_content_type',
21
  );
22
}
23

    
24
/**
25
 * Return each available mini panel available as a subtype.
26
 */
27
function panels_mini_panels_mini_content_type_content_type($subtype_id, $plugin) {
28
  $mini = panels_mini_load($subtype_id);
29
  return _panels_mini_panels_mini_content_type_content_type($mini);
30
}
31

    
32
/**
33
 * Return each available mini panel available as a subtype.
34
 */
35
function panels_mini_panels_mini_content_type_content_types($plugin) {
36
  $types = array();
37
  foreach (panels_mini_load_all() as $mini) {
38
    $type = _panels_mini_panels_mini_content_type_content_type($mini);
39
    if ($type) {
40
      $types[$mini->name] = $type;
41
    }
42
  }
43
  return $types;
44
}
45

    
46
/**
47
 * Return an info array describing a single mini panel.
48
 */
49
function _panels_mini_panels_mini_content_type_content_type($mini) {
50
  if (empty($mini)) {
51
    // The mini panel is deleted or missing.
52
    return;
53
  }
54

    
55
  if (!empty($mini->disabled)) {
56
    return;
57
  }
58

    
59
  $title = filter_xss_admin($mini->admin_title);
60
  $type = array(
61
    'title' => $title,
62
    // For now mini panels will just use the contrib block icon.
63
    'icon' => 'icon_mini_panel.png',
64
    'description' => $title,
65
    'category' => !empty($mini->category) ? $mini->category : t('Mini panel'),
66
  );
67
  if (!empty($mini->requiredcontexts)) {
68
    $type['required context'] = array();
69
    foreach ($mini->requiredcontexts as $context) {
70
      $info = ctools_get_context($context['name']);
71
      // Check if the required context is actually required.
72
      if (!empty($context['optional'])) {
73
        $type['required context'][] = new ctools_context_optional($context['identifier'], $info['context name']);
74
      }
75
      else {
76
        $type['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
77
      }
78
    }
79
  }
80
  return $type;
81
}
82

    
83
/**
84
 * Render a mini panel called from a panels display.
85
 */
86
function panels_mini_panels_mini_content_type_render($subtype, $conf, $panel_args, &$contexts) {
87
  static $viewing = array();
88
  $mini = panels_mini_load($subtype);
89
  if (!$mini) {
90
    return FALSE;
91
  }
92
  if (!empty($viewing[$mini->name])) {
93
    return FALSE;
94
  }
95

    
96
  // Load up any contexts we might be using.
97
  $context = ctools_context_match_required_contexts($mini->requiredcontexts, $contexts);
98
  $mini->context = $mini->display->context = ctools_context_load_contexts($mini, FALSE, $context);
99

    
100
  if (empty($mini) || !empty($mini->disabled)) {
101
    return;
102
  }
103
  $viewing[$mini->name] = TRUE;
104

    
105
  $mini->display->args = $panel_args;
106
  $mini->display->css_id = panels_mini_get_id($subtype);
107
  $mini->display->owner = $mini;
108
  // unique ID of this mini.
109
  $mini->display->owner->id = $mini->name;
110

    
111
  $block = new stdClass();
112
  $block->module  = 'panels_mini';
113
  $block->delta   = $subtype;
114
  $block->content = panels_render_display($mini->display);
115
  $block->title = $mini->display->get_title();
116

    
117
  if (user_access('administer mini panels')) {
118
    $block->admin_links = array(
119
      array(
120
        'title' => t('Configure mini panel'),
121
        'href' => "admin/structure/mini-panels/list/$subtype/edit/content",
122
        'query' => drupal_get_destination(),
123
      ),
124
    );
125
  }
126

    
127
  unset($viewing[$mini->name]);
128
  return $block;
129
}
130

    
131
/**
132
 * Edit form for the mini panel content type.
133
 */
134
function panels_mini_panels_mini_content_type_edit_form($form, &$form_state) {
135
  // Empty form to ensure we have the override title + context gadgets.
136
  return $form;
137
}
138

    
139
/**
140
 * Provide the administrative title of a mini panel.
141
 */
142
function panels_mini_panels_mini_content_type_admin_title($subtype, $conf) {
143
  $mini = panels_mini_load($subtype);
144
  if (!$mini) {
145
    return t('Deleted/missing mini panel @name', array('@name' => $subtype));
146
  }
147

    
148
  $title = filter_xss_admin($mini->admin_title);
149
  if (empty($title)) {
150
    $title = t('Untitled mini panel');
151
  }
152
  return $title;
153
}
154

    
155
/**
156
 * Callback to provide administrative info. Provide links to edit the mini
157
 * panel.
158
 */
159
function panels_mini_panels_mini_content_type_admin_info($subtype, $conf) {
160
  $mini = panels_mini_load($subtype);
161
  if (!$mini) {
162
    return FALSE;
163
  }
164

    
165
  $block = new stdClass();
166
  $block->title = $mini->admin_title;
167
  $admin_pages = array(
168
    t('Settings') => 'basic',
169
    t('Context') => 'context',
170
    t('Layout') => 'layout',
171
    t('Content') => 'content',
172
  );
173

    
174
  $links = array();
175
  foreach ($admin_pages as $title => $tail) {
176
    $links[] = l($title, 'admin/structure/mini-panels/list/' . $subtype . '/edit/' . $tail, array('query' => drupal_get_destination()));
177
  }
178

    
179
  $block->content = theme('item_list', array('items' => $links));
180
  return $block;
181
}