5 * Definition of views_handler_field_file_extension.
9 * Returns a pure file extension of the file, for example 'module'.
10 * @ingroup views_field_handlers
12 class views_handler_field_file_extension extends views_handler_field {
13 public function option_definition() {
14 $options = parent::option_definition();
15 $options['extension_detect_tar'] = array('default' => FALSE, 'bool' => TRUE);
19 public function options_form(&$form, &$form_state) {
20 parent::options_form($form, $form_state);
21 $form['extension_detect_tar'] = array(
22 '#type' => 'checkbox',
23 '#title' => t('Detect if tar is part of the extension'),
24 '#description' => t("See if the previous extension is '.tar' and if so, add that, so we see 'tar.gz' or 'tar.bz2' instead of just 'gz'."),
25 '#default_value' => $this->options['extension_detect_tar'],
29 function render($values) {
30 $value = $this->get_value($values);
31 if (!$this->options['extension_detect_tar']) {
32 if (preg_match('/\.([^\.]+)$/', $value, $match)) {
33 return $this->sanitize_value($match[1]);
37 $file_parts = explode('.', basename($value));
38 // If there is an extension.
39 if (count($file_parts) > 1) {
40 $extension = array_pop($file_parts);
41 $last_part_in_name = array_pop($file_parts);
42 if ($last_part_in_name === 'tar') {
43 $extension = 'tar.' . $extension;
45 return $this->sanitize_value($extension);