Projet

Général

Profil

Paste
Télécharger (2,18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / contexts / string.inc @ 96a203dd

1
<?php
2

    
3
/**
4
 * @file
5
 *
6
 * Plugin to provide a string context
7
 */
8

    
9
/**
10
 * Plugins are described by creating a $plugin array which will be used
11
 * by the system that includes this file.
12
 */
13
$plugin = array(
14
  'title' => t('String'),
15
  'description' => t('A context that is just a string.'),
16
  'context' => 'ctools_context_create_string',
17
  'edit form' => 'ctools_context_string_settings_form',
18
  'defaults' => '',
19
  'keyword' => 'string',
20
  'no ui' => FALSE,
21
  'context name' => 'string',
22
  'convert list' => array(
23
    'raw' => t('Raw string'),
24
    'html_safe' => t('HTML-safe string'),
25
  ),
26
  'convert' => 'ctools_context_string_convert',
27
  'placeholder form' => array(
28
    '#type' => 'textfield',
29
    '#description' => t('Enter the string for this context.'),
30
  ),
31
);
32

    
33
/**
34
 * It's important to remember that $conf is optional here, because contexts
35
 * are not always created from the UI.
36
 */
37
function ctools_context_create_string($empty, $data = NULL, $conf = FALSE) {
38
  // The input is expected to be an object as created by ctools_break_phrase
39
  // which contains a group of string.
40

    
41
  $context = new ctools_context('string');
42
  $context->plugin = 'string';
43

    
44
  if ($empty) {
45
    return $context;
46
  }
47

    
48
  if ($data !== FALSE ) {
49
    // Support the array storage from the settings form but also handle direct input from arguments.
50
    $context->data = is_array($data) ? $data['string'] : $data;
51
    $context->title = ($conf) ? check_plain($data['identifier']) : check_plain($data);
52
    return $context;
53
  }
54
}
55

    
56
/**
57
 * Convert a context into a string.
58
 */
59
function ctools_context_string_convert($context, $type) {
60
  switch ($type) {
61
    case 'raw':
62
      return $context->data;
63
    case 'html_safe':
64
      return check_plain($context->data);
65
  }
66
}
67

    
68
/**
69
 * String settings form.
70
 */
71
function ctools_context_string_settings_form($form, &$form_state) {
72
  $conf = &$form_state['conf'];
73

    
74
  $form['string'] = array(
75
    '#title' => t('Enter the string'),
76
    '#type' => 'textfield',
77
    '#maxlength' => 512,
78
    '#weight' => -10,
79
    '#default_value' => $conf['string'],
80
  );
81

    
82
  return $form;
83
}
84

    
85
function ctools_context_string_settings_form_submit($form, &$form_state) {
86
  $form_state['conf']['string'] = $form_state['values']['string'];
87
}