Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / ctools_plugin_example / plugins / content_types / relcontext_content_type.inc @ 7e72b748

1
<?php
2

    
3
/**
4
 * @file
5
 * Content type that displays the relcontext context type.
6
 *
7
 * This example is for use with the relcontext relationship to show
8
 * how we can get a relationship-context into a data type.
9
 */
10

    
11
/**
12
 * Plugins are described by creating a $plugin array which will be used
13
 * by the system that includes this file.
14
 */
15
$plugin = array(
16
  // Used in add content dialogs.
17
  'title' => t('CTools example relcontext content type'),
18
  'admin info' => 'ctools_plugin_example_relcontext_content_type_admin_info',
19
  'content_types' => 'relcontext_content_type',
20
  'single' => TRUE,
21
  'render callback' => 'relcontext_content_type_render',
22
  // Icon goes in the directory with the content type. Here, in plugins/content_types.
23
  'icon' => 'icon_example.png',
24
  'description' => t('Relcontext content type - works with relcontext context.'),
25
  'required context' => new ctools_context_required(t('Relcontext'), 'relcontext'),
26
  'category' => array(t('CTools Examples'), -9),
27
  'edit form' => 'relcontext_edit_form',
28

    
29
  // This example does not provide 'admin info', which would populate the
30
  // panels builder page preview.
31
);
32

    
33
/**
34
 * Run-time rendering of the body of the block.
35
 *
36
 * @param $subtype
37
 * @param $conf
38
 *   Configuration as done at admin time
39
 * @param $args
40
 * @param $context
41
 *   Context - in this case we don't have any
42
 *
43
 * @return
44
 *   An object with at least title and content members
45
 */
46
function relcontext_content_type_render($subtype, $conf, $args, $context) {
47
  $data = $context->data;
48
  $block = new stdClass();
49

    
50
  // Don't forget to check this data if it's untrusted.
51
  // The title actually used in rendering.
52
  $block->title = "Relcontext content type";
53
  $block->content = t("
54
    This is a block of data created by the Relcontent content type.
55
    Data in the block may be assembled from static text (like this) or from the
56
    content type settings form (\$conf) for the content type, or from the context
57
    that is passed in. <br />
58
    In our case, the configuration form (\$conf) has just one field, 'config_item_1;
59
    and it's configured with:
60
    ");
61
  if (!empty($conf)) {
62
    $block->content .= '<div style="border: 1px solid red;">' . var_export($conf['config_item_1'], TRUE) . '</div>';
63
  }
64
  if (!empty($context)) {
65
    $block->content .= '<br />The args ($args) were <div style="border: 1px solid yellow;" >' .
66
      var_export($args, TRUE) . '</div>';
67
  }
68
  $block->content .= '<br />And the relcontext context  ($context->data->description)
69
    (which was created from a
70
    simplecontext context) was <div style="border: 1px solid green;" >' .
71
    print_r($context->data->description, TRUE) . '</div>';
72
  return $block;
73
}
74

    
75
/**
76
 * 'Edit' callback for the content type.
77
 * This example just returns a form.
78
 */
79
function relcontext_edit_form($form, &$form_state) {
80
  $conf = $form_state['conf'];
81

    
82
  $form['config_item_1'] = array(
83
    '#type' => 'textfield',
84
    '#title' => t('Config Item 1 (relcontext)'),
85
    '#size' => 50,
86
    '#description' => t('Setting for relcontext.'),
87
    '#default_value' => !empty($conf['config_item_1']) ? $conf['config_item_1'] : '',
88
    '#prefix' => '<div class="clear-block no-float">',
89
    '#suffix' => '</div>',
90
  );
91
  return $form;
92
}
93

    
94
function relcontext_edit_form_submit($form, &$form_state) {
95
  foreach (element_children($form) as $key) {
96
    if (!empty($form_state['values'][$key])) {
97
      $form_state['conf'][$key] = $form_state['values'][$key];
98
    }
99
  }
100
}