Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / term_context / term_name.inc @ e4c061ad

1
<?php
2

    
3
/**
4
 * Plugins are described by creating a $plugin array which will be used
5
 * by the system that includes this file.
6
 */
7
$plugin = array(
8
  'single' => TRUE,
9
  'title' => t('Term name'),
10
  'icon' => 'icon_term.png',
11
  'description' => t('The name of this taxonomy term.'),
12
  'required context' => new ctools_context_required(t('Term'), array('term', 'taxonomy_term')),
13
  'category' => t('Taxonomy term'),
14
  'defaults' => array(
15
    'link' => TRUE,
16
    'markup' => 'none',
17
    'id' => '',
18
    'class' => '',
19
  ),
20
);
21

    
22

    
23
/**
24
 * Render the custom content type.
25
 */
26
function ctools_term_name_content_type_render($subtype, $conf, $panel_args, $context) {
27
  if (empty($context) || empty($context->data)) {
28
    return;
29
  }
30

    
31
  // Get a shortcut to the term.
32
  $term = $context->data;
33

    
34
  // Load the vocabulary.
35
  $vocab = taxonomy_vocabulary_load($term->vid);
36

    
37
  // Generate the title
38
  $content = !empty($conf['link']) ? l($term->name, 'taxonomy/term/' . $term->tid) : check_plain($term->name);
39

    
40
  // Build any surrounding markup if so configured
41
  if (isset($conf['markup']) && $conf['markup'] != 'none') {
42
    $markup = '<' . $conf['markup'];
43
    if (!empty($conf['id'])) {
44
      $markup .= ' id="' . $conf['id'] . '"';
45
    }
46
    if (!empty($conf['class'])) {
47
      $markup .= ' class="' . $conf['class'] . '"';
48
    }
49
    $markup .= '>' . $content . '</' . $conf['markup'] . '>' . "\n";
50
    $content = $markup;
51
  }
52

    
53
  // Build the content type block.
54
  $block = new stdClass();
55
  $block->module  = 'term_name';
56
  $block->title   = t('Name');
57
  $block->content = $content;
58
  $block->delta   = $term->tid;
59

    
60
  return $block;
61
}
62

    
63
/**
64
 * Returns an edit form for custom type settings.
65
 */
66
function ctools_term_name_content_type_edit_form($form, &$form_state) {
67
  $conf = $form_state['conf'];
68

    
69
  $form['markup'] = array(
70
    '#title' => t('Title tag'),
71
    '#type' => 'select',
72
    '#options' => array(
73
      'none' => t('- No tag -'),
74
      'h1' => t('h1'),
75
      'h2' => t('h2'),
76
      'h3' => t('h3'),
77
      'h4' => t('h4'),
78
      'h5' => t('h5'),
79
      'h6' => t('h6'),
80
      'div' => t('div'),
81
    ),
82
    '#default_value' => $conf['markup'],
83
  );
84

    
85
  $form['id'] = array(
86
    '#title' => t('CSS id to use'),
87
    '#type' => 'textfield',
88
    '#default_value' => $conf['id'],
89
  );
90

    
91
  $form['class'] = array(
92
    '#title' => t('CSS class to use'),
93
    '#type' => 'textfield',
94
    '#default_value' => $conf['class'],
95
  );
96

    
97
  $form['link'] = array(
98
    '#title' => t('Link to term'),
99
    '#type' => 'checkbox',
100
    '#default_value' => $conf['link'],
101
    '#description' => t('Check here to make the name link to the term page.'),
102
  );
103
  return $form;
104
}
105

    
106
/**
107
 * Submit handler for the custom type settings form.
108
 */
109
function ctools_term_name_content_type_edit_form_submit($form, &$form_state) {
110
  // Copy everything from our defaults.
111
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
112
    $form_state['conf'][$key] = $form_state['values'][$key];
113
  }
114
}
115

    
116
/**
117
 * Returns the administrative title for a type.
118
 */
119
function ctools_term_name_content_type_admin_title($subtype, $conf, $context) {
120
  return t('"@s" name', array('@s' => $context->identifier));
121
}