Révision 7b2d1845
Ajouté par Assos Assos il y a presque 4 ans
drupal7/sites/all/modules/file_entity/file_entity.pages.inc | ||
---|---|---|
122 | 122 |
* Generate form fields for the first step in the add file wizard. |
123 | 123 |
*/ |
124 | 124 |
function file_entity_add_upload_step_upload($form, &$form_state, array $options = array()) { |
125 |
$upload_validators = file_entity_get_upload_validators($options); |
|
125 | 126 |
$form['upload'] = array( |
126 | 127 |
'#type' => 'managed_file', |
127 | 128 |
'#title' => t('Upload a new file'), |
128 | 129 |
'#upload_location' => file_entity_upload_destination_uri($options), |
129 |
'#upload_validators' => file_entity_get_upload_validators($options),
|
|
130 |
'#upload_validators' => $upload_validators,
|
|
130 | 131 |
'#progress_indicator' => 'bar', |
131 | 132 |
'#required' => TRUE, |
132 | 133 |
'#pre_render' => array('file_managed_file_pre_render', 'file_entity_upload_validators_pre_render'), |
... | ... | |
139 | 140 |
$extensions = explode("\n", variable_get('file_entity_max_filesize_extensions')); |
140 | 141 |
|
141 | 142 |
if (!empty($extensions)) { |
143 |
$limits = array(); |
|
142 | 144 |
|
143 |
$limits = ''; |
|
145 |
// Limit extensions displayed to those in upload validator. |
|
146 |
$valid_extensions = array(); |
|
147 |
if (!empty($upload_validators)) { |
|
148 |
foreach ($upload_validators['file_validate_extensions'] as $key => $values) { |
|
149 |
$valid_extensions[$key] = explode(' ', strtolower($values)); |
|
150 |
} |
|
151 |
} |
|
152 |
// If there are valid extensions, merge sub-arrays into a single array. |
|
153 |
if (!empty($valid_extensions)) { |
|
154 |
$valid_extensions = call_user_func_array('array_merge', $valid_extensions); |
|
155 |
} |
|
144 | 156 |
|
145 | 157 |
foreach ($extensions as $position => $text) { |
146 | 158 |
$matches = array(); |
... | ... | |
150 | 162 |
$extension = $matches[1]; |
151 | 163 |
$filesize = $matches[2]; |
152 | 164 |
|
153 |
$limits .= $extension . ': ' . $filesize . ','; |
|
165 |
if (empty($valid_extensions) || in_array(strtolower($extension), $valid_extensions)) { |
|
166 |
$limits[] = trim($extension) . ': <strong>' . trim($filesize) . '</strong>'; |
|
167 |
} |
|
154 | 168 |
} |
155 | 169 |
} |
156 | 170 |
|
157 |
$limits = rtrim($limits, ','); |
|
158 |
|
|
159 |
$form['upload']['#description'] = t('Files must be less than !size (!limits).', array('!size' => '<strong>' . format_size($form['upload']['#upload_validators']['file_entity_validate_size_extensions'][0]) . '</strong>', '!limits' => $limits)); |
|
160 |
|
|
171 |
if (!empty($limits)) { |
|
172 |
// If less than or equal to 15 items to display, show as unordered list. |
|
173 |
// Otherwise, implode into a single list item. |
|
174 |
$list = array( |
|
175 |
'#theme' => 'item_list', |
|
176 |
'#list_type' => 'ul', |
|
177 |
'#items' => (count($limits) <= 15) ? $limits : array(implode(', ', $limits)), |
|
178 |
); |
|
179 |
|
|
180 |
if (!empty($valid_extensions)) { |
|
181 |
$form['upload']['#description'] = t('Files must be less than these sizes: !list', |
|
182 |
array( |
|
183 |
'!list' => render($list), |
|
184 |
) |
|
185 |
); |
|
186 |
} |
|
187 |
else { |
|
188 |
$form['upload']['#description'] = t('Files must be less than these sizes: !list The default maximum size is !size.', |
|
189 |
array( |
|
190 |
'!list' => render($list), |
|
191 |
'!size' => '<strong>' . format_size($form['upload']['#upload_validators']['file_entity_validate_size_extensions'][0]) . '</strong>' |
|
192 |
) |
|
193 |
); |
|
194 |
} |
|
195 |
} |
|
161 | 196 |
} |
162 | 197 |
|
163 | 198 |
$form['actions'] = array('#type' => 'actions'); |
... | ... | |
357 | 392 |
if (empty($label)) { |
358 | 393 |
$label = t('(entity label not loaded)'); |
359 | 394 |
} |
395 |
$entity_label = $label; |
|
360 | 396 |
$entity_uri = empty($entities[$entity_id]) ? NULL : entity_uri($entity_type, $entities[$entity_id]); |
361 | 397 |
|
362 | 398 |
// Link the label to the URI when possible. |
Formats disponibles : Unified diff
Weekly update of contrib modules