-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathle_ministre.module
executable file
·126 lines (107 loc) · 3.11 KB
/
le_ministre.module
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Implements hook_block_info().
*/
function le_ministre_block_info() {
$blocks = array();
$blocks['le_ministre'] = array(
'info' => t('A propos du Ministre'),
);
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function le_ministre_block_configure($delta='') {
$form = array();
switch($delta) {
case 'le_ministre' :
// Text field form element
$form['text_body'] = array(
'#type' => 'text_format',
'#title' => t('Enter your text here in WYSIWYG format'),
'#default_value' => variable_get('text_variable', ''),
);
// File selection form element
$form['file'] = array(
'#name' => 'block_image',
'#type' => 'managed_file',
'#title' => t('Choose an Image File'),
'#description' => t('Select an Image for the custom block. Only *.gif, *.png, *.jpg, and *.jpeg images allowed.'),
'#default_value' => variable_get('block_image_fid', ''),
'#upload_location' => 'public://block_image/',
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
);
break;
}
return $form;
}
/**
* Implements hook_block_save().
*/
function le_ministre_block_save($delta = '', $edit = array()) {
switch($delta) {
case 'le_ministre' :
// Saving the WYSIWYG text
variable_set('text_variable', $edit['text_body']['value']);
// Saving the file, setting it to a permanent state, setting a FID variable
$file = file_load($edit['file']);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
$block = block_load('le_ministre', $delta);
file_usage_add($file, 'le_ministre', 'block', $block->bid);
variable_set('block_image_fid', $file->fid);
break;
}
}
/**
* Implements hook_block_view().
*/
function le_ministre_block_view($delta='') {
$block = array();
switch($delta) {
case 'le_ministre' :
$block['content'] = my_block_view();
break;
}
return $block;
}
/**
* Custom function to assemble renderable array for block content.
* Returns a renderable array with the block content.
* @return
* returns a renderable array of block content.
*/
function my_block_view() {
$block = array();
// Capture the image file path and form into HTML with attributes
$image_file = file_load(variable_get('block_image_fid', ''));
$image_path = '';
if (isset($image_file->uri)) {
$image_path = $image_file->uri;
}
$image = theme_image(array(
'path' => ($image_path),
'alt' => t('Ministre de la fonction publique'),
'title' => t('Ministre de la fonction publique'),
'attributes' => array('class' => 'ministre-image'),
));
// Capture WYSIWYG text from the variable
$text = variable_get('text_variable', '');
// Block output in HTML with div wrapper
$block = array(
'image' => array(
'#prefix' => '<div class="wrap-minister">',
'#type' => 'markup',
'#markup' => $image,
),
'message' => array(
'#type' => 'markup',
'#markup' => $text,
'#suffix' => '</div>',
),
);
return $block;
}