Projet

Général

Profil

Paste
Télécharger (4,86 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / file_entity / plugins / content_types / file_display.inc @ 27370441

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('File display'),
10
  'description' => t('Displays the file with a configurable style.'),
11
  'required context' => new ctools_context_required(t('File'), 'entity:file'),
12
  'category' => t('File'),
13
  'defaults' => array(
14
    'displays' => array(),
15
  ),
16
);
17

    
18
/**
19
 * Render the node content.
20
 */
21
function file_entity_file_display_content_type_render($subtype, $conf, $panel_args, $context) {
22
  if (!empty($context) && empty($context->data)) {
23
    return;
24
  }
25
  $file = isset($context->data) ? clone($context->data) : NULL;
26
  $block = new stdClass();
27
  $block->module = 'file_entity';
28
  $block->delta  = $file->fid;
29

    
30
  if (empty($file)) {
31
    $block->delta   = 'placeholder';
32
    $block->title = t('File display');
33
    $block->content = t('File display goes here.');
34
  }
35
  else {
36
    if (!empty($conf['identifier'])) {
37
      $file->ctools_template_identifier = $conf['identifier'];
38
    }
39

    
40
    $block->title = $file->filename;
41
    $block->content = file_view_file($file, $conf['displays']);
42
  }
43

    
44
  if (!empty($conf['link']) && $file) {
45
    $block->title_link = entity_uri('file', $file);
46
  }
47

    
48
  return $block;
49
}
50

    
51
/**
52
 * Edit form for this plugin.
53
 */
54
function file_entity_file_display_content_type_edit_form($form, &$form_state) {
55
  $conf = $form_state['conf'];
56
  $form['#tree'] = TRUE;
57
  $form['#attached']['js'][] = drupal_get_path('module', 'file_entity') . '/file_entity.admin.js';
58

    
59
  // Retrieve available formatters for this file. We can load all file types
60
  // since we don't know which type the file is at this point.
61
  $formatters = file_info_formatter_types();
62

    
63
  // Formatter status.
64
  $form['displays']['status'] = array(
65
    '#type' => 'item',
66
    '#title' => t('Enabled displays'),
67
    '#prefix' => '<div id="file-displays-status-wrapper">',
68
    '#suffix' => '</div>',
69
  );
70
  $i=0;
71
  foreach ($formatters as $name => $formatter) {
72
    $form['displays']['status'][$name] = array(
73
      '#type' => 'checkbox',
74
      '#title' => check_plain($formatter['label']),
75
      '#default_value' => !empty($conf['displays'][$name]['status']),
76
      '#description' => isset($formatter['description']) ? filter_xss($formatter['description']) : NULL,
77
      '#parents' => array('displays', $name, 'status'),
78
      '#weight' => (isset($formatter['weight']) ? $formatter['weight'] : 0) + ($i / 1000),
79
    );
80
    $i++;
81
  }
82
  // Formatter order (tabledrag).
83
  $form['displays']['order'] = array(
84
    '#type' => 'item',
85
    '#title' => t('Display precedence order'),
86
    '#theme' => 'file_entity_file_display_order',
87
  );
88
  foreach ($formatters as $name => $formatter) {
89
    $form['displays']['order'][$name]['label'] = array(
90
      '#markup' => check_plain($formatter['label']),
91
    );
92
    $form['displays']['order'][$name]['weight'] = array(
93
      '#type' => 'weight',
94
      '#title' => t('Weight for @title', array('@title' => $formatter['label'])),
95
      '#title_display' => 'invisible',
96
      '#delta' => 50,
97
      '#default_value' => isset($conf['displays'][$name]['weight']) ? $conf['displays'][$name]['weight'] : 0,
98
      '#parents' => array('displays', $name, 'weight'),
99
    );
100
    $form['displays']['order'][$name]['#weight'] = $form['displays']['order'][$name]['weight']['#default_value'];
101
  }
102

    
103
  // Formatter settings.
104
  $form['display_settings_title'] = array(
105
    '#type' => 'item',
106
    '#title' => t('Display settings'),
107
  );
108
  $form['display_settings'] = array(
109
    '#type' => 'vertical_tabs',
110
  );
111
  $i=0;
112
  foreach ($formatters as $name => $formatter) {
113
    if (isset($formatter['settings callback']) && ($function = $formatter['settings callback']) && function_exists($function)) {
114
      $defaults = !empty($formatter['default settings']) ? $formatter['default settings'] : array();
115
      $settings = !empty($conf['displays'][$name]['settings']) ? $conf['displays'][$name]['settings'] : array();
116
      $settings += $defaults;
117
      $settings_form = $function($form, $form_state, $settings, $name, $file_type, $view_mode);
118
      if (!empty($settings_form)) {
119
        $form['displays']['settings'][$name] = array(
120
          '#type' => 'fieldset',
121
          '#title' => check_plain($formatter['label']),
122
          '#parents' => array('displays', $name, 'settings'),
123
          '#group' => 'display_settings',
124
          '#weight' => (isset($formatter['weight']) ? $formatter['weight'] : 0) + ($i / 1000),
125
        ) + $settings_form;
126
      }
127
    }
128
    $i++;
129
  }
130
  return $form;
131
}
132

    
133
function file_entity_file_display_content_type_edit_form_submit($form, &$form_state) {
134
  // Copy everything from our defaults.
135
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
136
    $form_state['conf'][$key] = $form_state['values'][$key];
137
  }
138
}
139

    
140
function file_entity_file_display_content_type_admin_title($subtype, $conf, $context) {
141
  return t('"@s" content', array('@s' => $context->identifier));
142
}