summaryrefslogtreecommitdiff
path: root/sites/all/modules/ds/plugins/content_types/dsc/dsc.inc
blob: ead5bf425e6786f9634f9071b5a648652ec2ca9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php

/**
 * @file
 * Plugin to handle the Display Suite content type.
 */

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = array(
  'title' => t('Display Suite content'),
  'category' => t('Display Suite'),
  'single' => TRUE,
  'defaults' => array(
    'title' => '',
    'body' => '',
    'format' => 'ds_code',
    'context' => array(),
  ),
  'description' => t('Add custom content with the possibility to use the entity object when using the Display Suite format.'),
  'js' => array('misc/textarea.js', 'misc/collapse.js'),
  'all contexts' => TRUE,
);

/**
 * Output function for the 'Display Suite' content type.
 */
function ds_dsc_content_type_render($subtype, $conf, $panel_args, $context, $incoming) {
  $block = new stdClass();

  $field = array();

  $entity = array_shift($context);
  $field['entity'] = isset($entity->data) ? $entity->data : NULL;
  $field['properties']['code']['format'] = $conf['format'];
  $field['properties']['code']['value'] = $conf['body'];

  $block->module = 'ds';
  $block->title = $conf['title'];
  $block->content = ds_render_code_field($field);

  return $block;
}

/**
 * The form to add or edit Display Suite content.
 */
function ds_dsc_content_type_edit_form($form, &$form_state) {
  $conf = $form_state['conf'];

  $form['title'] = array(
    '#type' => 'textfield',
    '#default_value' => isset($conf['title']) ? $conf['title'] : '',
    '#title' => t('Title'),
  );

  $form['body'] = array(
    '#type' => 'text_format',
    '#title' => t('Body'),
    '#default_value' => isset($conf['body']) ? $conf['body'] : '',
    '#format' => isset($conf['format']) ? $conf['format'] : 'ds_code',
  );

  return $form;
}

/**
 * Save the Display Suite content.
 */
function ds_dsc_content_type_edit_form_submit($form, &$form_state) {
  $form_state['conf']['title'] = $form_state['values']['title'];
  $form_state['conf']['body'] = $form_state['values']['body']['value'];
  $form_state['conf']['format'] = $form_state['values']['body']['format'];
  $form_state['conf']['context'] = array();
}

/**
 * Returns the administrative title for a Display Suite content.
 */
function ds_dsc_content_type_admin_title($subtype, $conf) {
  return (!empty($conf['title'])) ? $conf['title'] : t('Display Suite content');
}

/**
 * Display the administrative information for a Display Suite content pane.
 */
function ds_dsc_content_type_admin_info($subtype, $conf) {
  return 'Display Suite content can only be rendered on the frontend.';
}