5 * Plugin automatically declare 'tokens' as plugins.
12 'title' => t('Tokens'),
13 'content type' => 'ctools_token_content_type_content_type',
14 'defaults' => array('sanitize' => TRUE),
20 * Ordinarily this function is meant to get just one subtype. However, we are
21 * using it to deal with the fact that we have changed the subtype names. This
22 * lets us translate the name properly.
24 function ctools_token_content_type_content_type($subtype) {
25 $types = ctools_token_content_type_content_types();
26 if (isset($types[$subtype])) {
27 return $types[$subtype];
32 * Return all field content types available.
34 function ctools_token_content_type_content_types() {
35 // This will hold all the properties.
36 $types = &drupal_static(__FUNCTION__);
44 foreach ($info['tokens'] as $entity_type => $tokens) {
45 $category = t('@entity (tokens)', array('@entity' => ucfirst($entity_type)));
46 $context = new ctools_context_required(t(ucfirst($entity_type)), $entity_type);
47 foreach ($tokens as $name => $token) {
48 if (!empty($token['name'])) {
49 $token += array('description' => '');
50 $types[$entity_type . ':' . $name] = array(
51 'category' => $category,
52 'icon' => 'icon_token.png',
53 'title' => $token['name'],
54 'description' => $token['description'],
55 'required context' => $context,
65 * Render the custom content type.
67 function ctools_token_content_type_render($subtype, $conf, $panel_args, $context) {
68 if (empty($context) || empty($context->data)) {
72 $sanitize = $conf['sanitize'];
74 $entity = $context->data;
75 list($entity_type, $name) = explode(':', $subtype, 2);
78 $values = token_generate($entity_type, array($name => $name), array($entity_type => $entity), array('sanitize' => $sanitize));
79 if (!isset($values[$name])) {
83 // Build the content type block.
84 $block = new stdClass();
85 $block->module = 'ctools';
86 $block->title = $info['tokens'][$entity_type][$name]['name'];
87 $block->content = $values[$name];
88 $block->delta = str_replace('_', '-', $entity_type . '-' . $name);
94 * Returns an edit form for custom type settings.
96 function ctools_token_content_type_edit_form($form, &$form_state) {
97 $conf = $form_state['conf'];
99 $form['sanitize'] = array(
100 '#type' => 'checkbox',
101 '#default_value' => !empty($conf['sanitize']),
102 '#title' => t('Sanitize'),
103 '#description' => t('When enabled that output of the token will be stripped from dangerous HTML.'),
110 * Validate the node selection.
112 function ctools_token_content_type_edit_form_submit($form, &$form_state) {
113 $form_state['conf']['sanitize'] = $form_state['values']['sanitize'];
118 * Returns the administrative title for a type.
120 function ctools_token_content_type_admin_title($subtype, $conf, $context) {
121 return t('"@s" @name', array('@s' => $context->identifier, '@name' => $subtype));