From 713f5951382fea8c2c9b43b9d9871635a1990683 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 13 Jan 2010 00:07:47 +0000 Subject: [PATCH] MINOR implement the allowedExtensions functionality of AssetAdmin when you rename a file (from r92037) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@96814 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/AssetTableField.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/AssetTableField.php b/code/AssetTableField.php index 44bb612a..69dd471a 100755 --- a/code/AssetTableField.php +++ b/code/AssetTableField.php @@ -247,6 +247,30 @@ class AssetTableField extends ComplexTableField { return $fieldContainer->FieldHolder(); } + function handleItem($request) { + return new AssetTableField_ItemRequest($this, $request->param('ID')); + } } +class AssetTableField_ItemRequest extends ComplexTableField_ItemRequest { + function saveComplexTableField($data, $form, $request) { + + if(!AssetAdmin::$apply_restrictions_to_admin && Permission::check('ADMIN')) { + if(!in_array(strtolower(pathinfo($data['Name'], PATHINFO_EXTENSION)), AssetAdmin::$allowed_extensions)) { + $form->sessionMessage(sprintf( + _t( + 'File.INVALIDEXTENSION', + 'Extension is not allowed (valid: %s)', + PR_MEDIUM, + 'Argument 1: Comma-separated list of valid extensions' + ), + implode(',',AssetAdmin::$allowed_extensions) + ), 'bad'); + Director::redirectBack(); + return; + } + } + return parent::saveComplexTableField($data, $form, $request); + } +} ?>