1 |
85ad3d82
|
Assos Assos
|
<?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 content'),
|
10 |
|
|
'description' => t('Display a full file with a view mode.'),
|
11 |
|
|
'required context' => new ctools_context_required(t('File'), 'entity:file'),
|
12 |
|
|
'category' => t('File'),
|
13 |
|
|
'defaults' => array(
|
14 |
|
|
'link' => FALSE,
|
15 |
|
|
'view_mode' => 'teaser',
|
16 |
|
|
),
|
17 |
|
|
);
|
18 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Render the node content.
|
21 |
|
|
*/
|
22 |
|
|
function file_entity_file_content_content_type_render($subtype, $conf, $panel_args, $context) {
|
23 |
|
|
if (!empty($context) && empty($context->data)) {
|
24 |
|
|
return;
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
$file = isset($context->data) ? clone($context->data) : NULL;
|
28 |
|
|
$block = new stdClass();
|
29 |
|
|
$block->module = 'file_entity';
|
30 |
|
|
$block->delta = $file->fid;
|
31 |
|
|
|
32 |
|
|
if (empty($file)) {
|
33 |
|
|
$block->delta = 'placeholder';
|
34 |
|
|
$block->title = t('File title.');
|
35 |
|
|
$block->content = t('File content goes here.');
|
36 |
|
|
}
|
37 |
|
|
else {
|
38 |
|
|
if (!empty($conf['identifier'])) {
|
39 |
|
|
$node->ctools_template_identifier = $conf['identifier'];
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
$block->title = $file->filename;
|
43 |
|
|
$block->content = file_build_content($file, $conf['view_mode']);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
if (!empty($conf['link']) && $file) {
|
47 |
|
|
$block->title_link = entity_uri('file', $file);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
return $block;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Returns an edit form for this plugin.
|
55 |
|
|
*/
|
56 |
|
|
function file_entity_file_content_content_type_edit_form($form, &$form_state) {
|
57 |
|
|
$conf = $form_state['conf'];
|
58 |
|
|
|
59 |
|
|
$form['link'] = array(
|
60 |
|
|
'#title' => t('Link title to file'),
|
61 |
|
|
'#type' => 'checkbox',
|
62 |
|
|
'#default_value' => $conf['link'],
|
63 |
|
|
'#description' => t('Check this to make the title link to the file.'),
|
64 |
|
|
);
|
65 |
|
|
|
66 |
|
|
$entity_info = entity_get_info('file');
|
67 |
|
|
$build_mode_options = array();
|
68 |
|
|
foreach ($entity_info['view modes'] as $mode => $option) {
|
69 |
|
|
$build_mode_options[$mode] = $option['label'];
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
$form['view_mode'] = array(
|
73 |
|
|
'#title' => t('View mode'),
|
74 |
|
|
'#type' => 'select',
|
75 |
|
|
'#description' => t('Select a view mode for this node.'),
|
76 |
|
|
'#options' => $build_mode_options,
|
77 |
|
|
'#default_value' => $conf['view_mode'],
|
78 |
|
|
);
|
79 |
|
|
|
80 |
|
|
return $form;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
function file_entity_file_content_content_type_edit_form_submit($form, &$form_state) {
|
84 |
|
|
// Copy everything from our defaults.
|
85 |
|
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
86 |
|
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
function file_entity_file_content_content_type_admin_title($subtype, $conf, $context) {
|
91 |
|
|
return t('"@s" content', array('@s' => $context->identifier));
|
92 |
|
|
} |