From 60981b1b787bef1a8a4fa64fe5fbe84a7f9ca5d5 Mon Sep 17 00:00:00 2001 From: Neil Drumm Date: Fri, 21 Sep 2012 16:25:37 -0700 Subject: [PATCH] [#1791970] Show tar.gz as extension instead of gz --- lib/Views/file/Plugin/views/field/Extension.php | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Views/file/Plugin/views/field/Extension.php b/lib/Views/file/Plugin/views/field/Extension.php index 792bb13..4c1bde8 100644 --- a/lib/Views/file/Plugin/views/field/Extension.php +++ b/lib/Views/file/Plugin/views/field/Extension.php @@ -23,9 +23,17 @@ use Drupal\views\Plugin\views\field\FieldPluginBase; class Extension extends FieldPluginBase { function render($values) { - $value = $this->get_value($values); - if (preg_match('/\.([^\.]+)$/', $value, $match)) { - return $this->sanitizeValue($match[1]); + $file_parts = explode('.', basename($this->get_value($values))); + // If there is an extension. + if (count($file_parts) > 1) { + $ext = array_pop($file_parts); + // See if the previous extension is '.tar' and if so, add that, so we see + // 'tar.gz' or 'tar.bz2' instead of just 'gz'. + $ext2 = array_pop($file_parts); + if ($ext2 === 'tar') { + $ext = $ext2 . '.' . $ext; + } + return $this->sanitizeValue($ext); } } -- 1.7.5