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 @ 64156087

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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