Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like AssetAdmin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AssetAdmin, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 45 | class AssetAdmin extends LeftAndMain implements PermissionProvider  | 
            ||
| 46 | { | 
            ||
| 47 | private static $url_segment = 'assets';  | 
            ||
| 48 | |||
| 49 | private static $url_rule = '/$Action/$ID';  | 
            ||
| 50 | |||
| 51 | private static $menu_title = 'Files';  | 
            ||
| 52 | |||
| 53 | private static $menu_icon_class = 'font-icon-image';  | 
            ||
| 54 | |||
| 55 | private static $tree_class = 'SilverStripe\\Assets\\Folder';  | 
            ||
| 56 | |||
| 57 | private static $url_handlers = [  | 
            ||
| 58 | // Legacy redirect for SS3-style detail view  | 
            ||
| 59 | 'EditForm/field/File/item/$FileID/$Action' => 'legacyRedirectForEditView',  | 
            ||
| 60 | // Pass all URLs to the index, for React to unpack  | 
            ||
| 61 | 'show/$FolderID/edit/$FileID' => 'index',  | 
            ||
| 62 | // API access points with structured data  | 
            ||
| 63 | 'POST api/createFile' => 'apiCreateFile',  | 
            ||
| 64 | 'POST api/uploadFile' => 'apiUploadFile',  | 
            ||
| 65 | 'GET api/history' => 'apiHistory'  | 
            ||
| 66 | ];  | 
            ||
| 67 | |||
| 68 | /**  | 
            ||
| 69 | * Amount of results showing on a single page.  | 
            ||
| 70 | *  | 
            ||
| 71 | * @config  | 
            ||
| 72 | * @var int  | 
            ||
| 73 | */  | 
            ||
| 74 | private static $page_length = 15;  | 
            ||
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * @config  | 
            ||
| 78 | * @see Upload->allowedMaxFileSize  | 
            ||
| 79 | * @var int  | 
            ||
| 80 | */  | 
            ||
| 81 | private static $allowed_max_file_size;  | 
            ||
| 82 | |||
| 83 | /**  | 
            ||
| 84 | * @config  | 
            ||
| 85 | *  | 
            ||
| 86 | * @var int  | 
            ||
| 87 | */  | 
            ||
| 88 | private static $max_history_entries = 100;  | 
            ||
| 89 | |||
| 90 | /**  | 
            ||
| 91 | * @var array  | 
            ||
| 92 | */  | 
            ||
| 93 | private static $allowed_actions = array(  | 
            ||
| 94 | 'legacyRedirectForEditView',  | 
            ||
| 95 | 'apiCreateFile',  | 
            ||
| 96 | 'apiUploadFile',  | 
            ||
| 97 | 'apiHistory',  | 
            ||
| 98 | 'fileEditForm',  | 
            ||
| 99 | 'fileHistoryForm',  | 
            ||
| 100 | 'addToCampaignForm',  | 
            ||
| 101 | 'fileInsertForm',  | 
            ||
| 102 | 'schema',  | 
            ||
| 103 | 'fileSelectForm',  | 
            ||
| 104 | 'fileSearchForm',  | 
            ||
| 105 | );  | 
            ||
| 106 | |||
| 107 | private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';  | 
            ||
| 108 | |||
| 109 | private static $thumbnail_width = 400;  | 
            ||
| 110 | |||
| 111 | private static $thumbnail_height = 300;  | 
            ||
| 112 | |||
| 113 | /**  | 
            ||
| 114 | * Set up the controller  | 
            ||
| 115 | */  | 
            ||
| 116 | public function init()  | 
            ||
| 117 |     { | 
            ||
| 118 | parent::init();  | 
            ||
| 119 | |||
| 120 | Requirements::add_i18n_javascript(ASSET_ADMIN_DIR . '/client/lang', false, true);  | 
            ||
| 121 | Requirements::javascript(ASSET_ADMIN_DIR . "/client/dist/js/bundle.js");  | 
            ||
| 122 | Requirements::css(ASSET_ADMIN_DIR . "/client/dist/styles/bundle.css");  | 
            ||
| 123 | |||
| 124 |         CMSBatchActionHandler::register('delete', DeleteAssets::class, Folder::class); | 
            ||
| 125 | }  | 
            ||
| 126 | |||
| 127 | public function getClientConfig()  | 
            ||
| 128 |     { | 
            ||
| 129 | $baseLink = $this->Link();  | 
            ||
| 130 | return array_merge(parent::getClientConfig(), [  | 
            ||
| 131 | 'reactRouter' => true,  | 
            ||
| 132 | 'createFileEndpoint' => [  | 
            ||
| 133 | 'url' => Controller::join_links($baseLink, 'api/createFile'),  | 
            ||
| 134 | 'method' => 'post',  | 
            ||
| 135 | 'payloadFormat' => 'urlencoded',  | 
            ||
| 136 | ],  | 
            ||
| 137 | 'uploadFileEndpoint' => [  | 
            ||
| 138 | 'url' => Controller::join_links($baseLink, 'api/uploadFile'),  | 
            ||
| 139 | 'method' => 'post',  | 
            ||
| 140 | 'payloadFormat' => 'urlencoded',  | 
            ||
| 141 | ],  | 
            ||
| 142 | 'historyEndpoint' => [  | 
            ||
| 143 | 'url' => Controller::join_links($baseLink, 'api/history'),  | 
            ||
| 144 | 'method' => 'get',  | 
            ||
| 145 | 'responseFormat' => 'json',  | 
            ||
| 146 | ],  | 
            ||
| 147 | 'limit' => $this->config()->page_length,  | 
            ||
| 148 | 'form' => [  | 
            ||
| 149 | 'fileEditForm' => [  | 
            ||
| 150 |                     'schemaUrl' => $this->Link('schema/fileEditForm') | 
            ||
| 151 | ],  | 
            ||
| 152 | 'fileInsertForm' => [  | 
            ||
| 153 |                     'schemaUrl' => $this->Link('schema/fileInsertForm') | 
            ||
| 154 | ],  | 
            ||
| 155 | 'fileSelectForm' => [  | 
            ||
| 156 |                     'schemaUrl' => $this->Link('schema/fileSelectForm') | 
            ||
| 157 | ],  | 
            ||
| 158 | 'addToCampaignForm' => [  | 
            ||
| 159 |                     'schemaUrl' => $this->Link('schema/addToCampaignForm') | 
            ||
| 160 | ],  | 
            ||
| 161 | 'fileHistoryForm' => [  | 
            ||
| 162 |                     'schemaUrl' => $this->Link('schema/fileHistoryForm') | 
            ||
| 163 | ],  | 
            ||
| 164 | 'fileSearchForm' => [  | 
            ||
| 165 |                     'schemaUrl' => $this->Link('schema/fileSearchForm') | 
            ||
| 166 | ],  | 
            ||
| 167 | ],  | 
            ||
| 168 | ]);  | 
            ||
| 169 | }  | 
            ||
| 170 | |||
| 171 | /**  | 
            ||
| 172 | * Creates a single file based on a form-urlencoded upload.  | 
            ||
| 173 | *  | 
            ||
| 174 | * @param HTTPRequest $request  | 
            ||
| 175 | * @return HTTPRequest|HTTPResponse  | 
            ||
| 176 | */  | 
            ||
| 177 | public function apiCreateFile(HTTPRequest $request)  | 
            ||
| 178 |     { | 
            ||
| 179 | $data = $request->postVars();  | 
            ||
| 180 | |||
| 181 | // When creating new files, rename on conflict  | 
            ||
| 182 | $upload = $this->getUpload();  | 
            ||
| 183 | $upload->setReplaceFile(false);  | 
            ||
| 184 | |||
| 185 | // CSRF check  | 
            ||
| 186 | $token = SecurityToken::inst();  | 
            ||
| 187 | View Code Duplication |         if (empty($data[$token->getName()]) || !$token->check($data[$token->getName()])) { | 
            |
| 188 | return new HTTPResponse(null, 400);  | 
            ||
| 189 | }  | 
            ||
| 190 | |||
| 191 | // Check parent record  | 
            ||
| 192 | /** @var Folder $parentRecord */  | 
            ||
| 193 | $parentRecord = null;  | 
            ||
| 194 |         if (!empty($data['ParentID']) && is_numeric($data['ParentID'])) { | 
            ||
| 195 | $parentRecord = Folder::get()->byID($data['ParentID']);  | 
            ||
| 196 | }  | 
            ||
| 197 | $data['Parent'] = $parentRecord;  | 
            ||
| 198 | |||
| 199 |         $tmpFile = $request->postVar('Upload'); | 
            ||
| 200 | View Code Duplication |         if (!$upload->validate($tmpFile)) { | 
            |
| 201 | $result = ['message' => null];  | 
            ||
| 202 | $errors = $upload->getErrors();  | 
            ||
| 203 |             if ($message = array_shift($errors)) { | 
            ||
| 204 | $result['message'] = [  | 
            ||
| 205 | 'type' => 'error',  | 
            ||
| 206 | 'value' => $message,  | 
            ||
| 207 | ];  | 
            ||
| 208 | }  | 
            ||
| 209 | return (new HTTPResponse(json_encode($result), 400))  | 
            ||
| 210 |                 ->addHeader('Content-Type', 'application/json'); | 
            ||
| 211 | }  | 
            ||
| 212 | |||
| 213 | // TODO Allow batch uploads  | 
            ||
| 214 | $fileClass = File::get_class_for_file_extension(File::get_file_extension($tmpFile['name']));  | 
            ||
| 215 | /** @var File $file */  | 
            ||
| 216 | $file = Injector::inst()->create($fileClass);  | 
            ||
| 217 | |||
| 218 | // check canCreate permissions  | 
            ||
| 219 | View Code Duplication |         if (!$file->canCreate(null, $data)) { | 
            |
| 220 | $result = ['message' => [  | 
            ||
| 221 | 'type' => 'error',  | 
            ||
| 222 | 'value' => _t(  | 
            ||
| 223 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied',  | 
            ||
| 224 | 'You do not have permission to add files'  | 
            ||
| 225 | )  | 
            ||
| 226 | ]];  | 
            ||
| 227 | return (new HTTPResponse(json_encode($result), 403))  | 
            ||
| 228 |                 ->addHeader('Content-Type', 'application/json'); | 
            ||
| 229 | }  | 
            ||
| 230 | |||
| 231 | $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/');  | 
            ||
| 232 | View Code Duplication |         if (!$uploadResult) { | 
            |
| 233 | $result = ['message' => [  | 
            ||
| 234 | 'type' => 'error',  | 
            ||
| 235 | 'value' => _t(  | 
            ||
| 236 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed',  | 
            ||
| 237 | 'Failed to load file'  | 
            ||
| 238 | )  | 
            ||
| 239 | ]];  | 
            ||
| 240 | return (new HTTPResponse(json_encode($result), 400))  | 
            ||
| 241 |                 ->addHeader('Content-Type', 'application/json'); | 
            ||
| 242 | }  | 
            ||
| 243 | |||
| 244 | $file->ParentID = $parentRecord ? $parentRecord->ID : 0;  | 
            ||
| 245 | $file->write();  | 
            ||
| 246 | |||
| 247 | $result = [$this->getObjectFromData($file)];  | 
            ||
| 248 | |||
| 249 | return (new HTTPResponse(json_encode($result)))  | 
            ||
| 250 |             ->addHeader('Content-Type', 'application/json'); | 
            ||
| 251 | }  | 
            ||
| 252 | |||
| 253 | /**  | 
            ||
| 254 | * Upload a new asset for a pre-existing record. Returns the asset tuple.  | 
            ||
| 255 | *  | 
            ||
| 256 | * Note that conflict resolution is as follows:  | 
            ||
| 257 | * - If uploading a file with the same extension, we simply keep the same filename,  | 
            ||
| 258 | * and overwrite any existing files (same name + sha = don't duplicate).  | 
            ||
| 259 | * - If uploading a new file with a different extension, then the filename will  | 
            ||
| 260 | * be replaced, and will be checked for uniqueness against other File dataobjects.  | 
            ||
| 261 | *  | 
            ||
| 262 | * @param HTTPRequest $request Request containing vars 'ID' of parent record ID,  | 
            ||
| 263 | * and 'Name' as form filename value  | 
            ||
| 264 | * @return HTTPRequest|HTTPResponse  | 
            ||
| 265 | */  | 
            ||
| 266 | public function apiUploadFile(HTTPRequest $request)  | 
            ||
| 267 |     { | 
            ||
| 268 | $data = $request->postVars();  | 
            ||
| 269 | |||
| 270 | // When updating files, replace on conflict  | 
            ||
| 271 | $upload = $this->getUpload();  | 
            ||
| 272 | $upload->setReplaceFile(true);  | 
            ||
| 273 | |||
| 274 | // CSRF check  | 
            ||
| 275 | $token = SecurityToken::inst();  | 
            ||
| 276 | View Code Duplication |         if (empty($data[$token->getName()]) || !$token->check($data[$token->getName()])) { | 
            |
| 277 | return new HTTPResponse(null, 400);  | 
            ||
| 278 | }  | 
            ||
| 279 | $tmpFile = $data['Upload'];  | 
            ||
| 280 |         if (empty($data['ID']) || empty($tmpFile['name']) || !array_key_exists('Name', $data)) { | 
            ||
| 281 |             return new HTTPResponse('Invalid request', 400); | 
            ||
| 282 | }  | 
            ||
| 283 | |||
| 284 | // Check parent record  | 
            ||
| 285 | /** @var File $file */  | 
            ||
| 286 | $file = File::get()->byID($data['ID']);  | 
            ||
| 287 |         if (!$file) { | 
            ||
| 288 |             return new HTTPResponse('File not found', 404); | 
            ||
| 289 | }  | 
            ||
| 290 | $folder = $file->ParentID ? $file->Parent()->getFilename() : '/';  | 
            ||
| 291 | |||
| 292 | // If extension is the same, attempt to re-use existing name  | 
            ||
| 293 |         if (File::get_file_extension($tmpFile['name']) === File::get_file_extension($data['Name'])) { | 
            ||
| 294 | $tmpFile['name'] = $data['Name'];  | 
            ||
| 295 |         } else { | 
            ||
| 296 | // If we are allowing this upload to rename the underlying record,  | 
            ||
| 297 | // do a uniqueness check.  | 
            ||
| 298 | $renamer = $this->getNameGenerator($tmpFile['name']);  | 
            ||
| 299 |             foreach ($renamer as $name) { | 
            ||
| 300 | $filename = File::join_paths($folder, $name);  | 
            ||
| 301 |                 if (!File::find($filename)) { | 
            ||
| 302 | $tmpFile['name'] = $name;  | 
            ||
| 303 | break;  | 
            ||
| 304 | }  | 
            ||
| 305 | }  | 
            ||
| 306 | }  | 
            ||
| 307 | |||
| 308 | View Code Duplication |         if (!$upload->validate($tmpFile)) { | 
            |
| 309 | $result = ['message' => null];  | 
            ||
| 310 | $errors = $upload->getErrors();  | 
            ||
| 311 |             if ($message = array_shift($errors)) { | 
            ||
| 312 | $result['message'] = [  | 
            ||
| 313 | 'type' => 'error',  | 
            ||
| 314 | 'value' => $message,  | 
            ||
| 315 | ];  | 
            ||
| 316 | }  | 
            ||
| 317 | return (new HTTPResponse(json_encode($result), 400))  | 
            ||
| 318 |                 ->addHeader('Content-Type', 'application/json'); | 
            ||
| 319 | }  | 
            ||
| 320 | |||
| 321 |         try { | 
            ||
| 322 | $tuple = $upload->load($tmpFile, $folder);  | 
            ||
| 323 |         } catch (Exception $e) { | 
            ||
| 324 | $result = [  | 
            ||
| 325 | 'message' => [  | 
            ||
| 326 | 'type' => 'error',  | 
            ||
| 327 | 'value' => $e->getMessage(),  | 
            ||
| 328 | ]  | 
            ||
| 329 | ];  | 
            ||
| 330 | return (new HTTPResponse(json_encode($result), 400))  | 
            ||
| 331 |                 ->addHeader('Content-Type', 'application/json'); | 
            ||
| 332 | }  | 
            ||
| 333 | |||
| 334 |         if ($upload->isError()) { | 
            ||
| 335 | $result['message'] = [  | 
            ||
| 336 | 'type' => 'error',  | 
            ||
| 337 |                 'value' => implode(' ' . PHP_EOL, $upload->getErrors()), | 
            ||
| 338 | ];  | 
            ||
| 339 | return (new HTTPResponse(json_encode($result), 400))  | 
            ||
| 340 |                 ->addHeader('Content-Type', 'application/json'); | 
            ||
| 341 | }  | 
            ||
| 342 | |||
| 343 | $tuple['Name'] = basename($tuple['Filename']);  | 
            ||
| 344 | return (new HTTPResponse(json_encode($tuple)))  | 
            ||
| 345 |             ->addHeader('Content-Type', 'application/json'); | 
            ||
| 346 | }  | 
            ||
| 347 | |||
| 348 | /**  | 
            ||
| 349 | * Returns a JSON array for history of a given file ID. Returns a list of all the history.  | 
            ||
| 350 | *  | 
            ||
| 351 | * @param HTTPRequest $request  | 
            ||
| 352 | * @return HTTPResponse  | 
            ||
| 353 | */  | 
            ||
| 354 | public function apiHistory(HTTPRequest $request)  | 
            ||
| 355 |     { | 
            ||
| 356 | // CSRF check not required as the GET request has no side effects.  | 
            ||
| 357 |         $fileId = $request->getVar('fileId'); | 
            ||
| 358 | |||
| 359 |         if (!$fileId || !is_numeric($fileId)) { | 
            ||
| 360 | return new HTTPResponse(null, 400);  | 
            ||
| 361 | }  | 
            ||
| 362 | |||
| 363 | $class = File::class;  | 
            ||
| 364 | $file = DataObject::get($class)->byID($fileId);  | 
            ||
| 365 | |||
| 366 |         if (!$file) { | 
            ||
| 367 | return new HTTPResponse(null, 404);  | 
            ||
| 368 | }  | 
            ||
| 369 | |||
| 370 |         if (!$file->canView()) { | 
            ||
| 371 | return new HTTPResponse(null, 403);  | 
            ||
| 372 | }  | 
            ||
| 373 | |||
| 374 | $versions = Versioned::get_all_versions($class, $fileId)  | 
            ||
| 375 | ->limit($this->config()->max_history_entries)  | 
            ||
| 376 |             ->sort('Version', 'DESC'); | 
            ||
| 377 | |||
| 378 | $output = array();  | 
            ||
| 379 | $next = array();  | 
            ||
| 380 | $prev = null;  | 
            ||
| 381 | |||
| 382 | // swap the order so we can get the version number to compare against.  | 
            ||
| 383 | // i.e version 3 needs to know version 2 is the previous version  | 
            ||
| 384 |         $copy = $versions->map('Version', 'Version')->toArray(); | 
            ||
| 385 |         foreach (array_reverse($copy) as $k => $v) { | 
            ||
| 386 |             if ($prev) { | 
            ||
| 387 | $next[$v] = $prev;  | 
            ||
| 388 | }  | 
            ||
| 389 | |||
| 390 | $prev = $v;  | 
            ||
| 391 | }  | 
            ||
| 392 | |||
| 393 | $_cachedMembers = array();  | 
            ||
| 394 | |||
| 395 | /** @var File $version */  | 
            ||
| 396 |         foreach ($versions as $version) { | 
            ||
| 397 | $author = null;  | 
            ||
| 398 | |||
| 399 |             if ($version->AuthorID) { | 
            ||
| 400 |                 if (!isset($_cachedMembers[$version->AuthorID])) { | 
            ||
| 401 | $_cachedMembers[$version->AuthorID] = DataObject::get(Member::class)  | 
            ||
| 402 | ->byID($version->AuthorID);  | 
            ||
| 403 | }  | 
            ||
| 404 | |||
| 405 | $author = $_cachedMembers[$version->AuthorID];  | 
            ||
| 406 | }  | 
            ||
| 407 | |||
| 408 |             if ($version->canView()) { | 
            ||
| 409 |                 if (isset($next[$version->Version])) { | 
            ||
| 410 | $summary = $version->humanizedChanges(  | 
            ||
| 411 | $version->Version,  | 
            ||
| 412 | $next[$version->Version]  | 
            ||
| 413 | );  | 
            ||
| 414 | |||
| 415 | // if no summary returned by humanizedChanges, i.e we cannot work out what changed, just show a  | 
            ||
| 416 | // generic message  | 
            ||
| 417 |                     if (!$summary) { | 
            ||
| 418 |                         $summary = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.SAVEDFILE', "Saved file"); | 
            ||
| 419 | }  | 
            ||
| 420 |                 } else { | 
            ||
| 421 |                     $summary = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.UPLOADEDFILE', "Uploaded file"); | 
            ||
| 422 | }  | 
            ||
| 423 | |||
| 424 | $output[] = array(  | 
            ||
| 425 | 'versionid' => $version->Version,  | 
            ||
| 426 |                     'date_ago' => $version->dbObject('LastEdited')->Ago(), | 
            ||
| 427 |                     'date_formatted' => $version->dbObject('LastEdited')->Nice(), | 
            ||
| 428 |                     'status' => ($version->WasPublished) ? _t('File.PUBLISHED', 'Published') : '', | 
            ||
| 429 | 'author' => ($author)  | 
            ||
| 430 | ? $author->Name  | 
            ||
| 431 |                         : _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.UNKNOWN', "Unknown"), | 
            ||
| 432 | 'summary' => ($summary)  | 
            ||
| 433 | ? $summary  | 
            ||
| 434 |                         : _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.NOSUMMARY', "No summary available") | 
            ||
| 435 | );  | 
            ||
| 436 | }  | 
            ||
| 437 | }  | 
            ||
| 438 | |||
| 439 | return  | 
            ||
| 440 |             (new HTTPResponse(json_encode($output)))->addHeader('Content-Type', 'application/json'); | 
            ||
| 441 | }  | 
            ||
| 442 | |||
| 443 | /**  | 
            ||
| 444 | * Redirects 3.x style detail links to new 4.x style routing.  | 
            ||
| 445 | *  | 
            ||
| 446 | * @param HTTPRequest $request  | 
            ||
| 447 | */  | 
            ||
| 448 | public function legacyRedirectForEditView($request)  | 
            ||
| 456 | |||
| 457 | /**  | 
            ||
| 458 | * Given a file return the CMS link to edit it  | 
            ||
| 459 | *  | 
            ||
| 460 | * @param File $file  | 
            ||
| 461 | * @return string  | 
            ||
| 462 | */  | 
            ||
| 463 | public function getFileEditLink($file)  | 
            ||
| 476 | |||
| 477 | /**  | 
            ||
| 478 | * Get an asset renamer for the given filename.  | 
            ||
| 479 | *  | 
            ||
| 480 | * @param string $filename Path name  | 
            ||
| 481 | * @return AssetNameGenerator  | 
            ||
| 482 | */  | 
            ||
| 483 | protected function getNameGenerator($filename)  | 
            ||
| 488 | |||
| 489 | /**  | 
            ||
| 490 | * @todo Implement on client  | 
            ||
| 491 | *  | 
            ||
| 492 | * @param bool $unlinked  | 
            ||
| 493 | * @return ArrayList  | 
            ||
| 494 | */  | 
            ||
| 495 | public function breadcrumbs($unlinked = false)  | 
            ||
| 499 | |||
| 500 | |||
| 501 | /**  | 
            ||
| 502 | * Don't include class namespace in auto-generated CSS class  | 
            ||
| 503 | */  | 
            ||
| 504 | public function baseCSSClasses()  | 
            ||
| 508 | |||
| 509 | public function providePermissions()  | 
            ||
| 520 | |||
| 521 | /**  | 
            ||
| 522 | * Build a form scaffolder for this model  | 
            ||
| 523 | *  | 
            ||
| 524 |      * NOTE: Volatile api. May be moved to {@see LeftAndMain} | 
            ||
| 525 | *  | 
            ||
| 526 | * @param File $file  | 
            ||
| 527 | * @return FormFactory  | 
            ||
| 528 | */  | 
            ||
| 529 | public function getFormFactory(File $file)  | 
            ||
| 542 | |||
| 543 | /**  | 
            ||
| 544 | * The form is used to generate a form schema,  | 
            ||
| 545 | * as well as an intermediary object to process data through API endpoints.  | 
            ||
| 546 | * Since it's used directly on API endpoints, it does not have any form actions.  | 
            ||
| 547 |      * It handles both {@link File} and {@link Folder} records. | 
            ||
| 548 | *  | 
            ||
| 549 | * @param int $id  | 
            ||
| 550 | * @return Form  | 
            ||
| 551 | */  | 
            ||
| 552 | public function getFileEditForm($id)  | 
            ||
| 556 | |||
| 557 | /**  | 
            ||
| 558 | * Get file edit form  | 
            ||
| 559 | *  | 
            ||
| 560 | * @return Form  | 
            ||
| 561 | */  | 
            ||
| 562 | View Code Duplication | public function fileEditForm()  | 
            |
| 569 | |||
| 570 | /**  | 
            ||
| 571 | * The form is used to generate a form schema,  | 
            ||
| 572 | * as well as an intermediary object to process data through API endpoints.  | 
            ||
| 573 | * Since it's used directly on API endpoints, it does not have any form actions.  | 
            ||
| 574 |      * It handles both {@link File} and {@link Folder} records. | 
            ||
| 575 | *  | 
            ||
| 576 | * @param int $id  | 
            ||
| 577 | * @return Form  | 
            ||
| 578 | */  | 
            ||
| 579 | public function getFileInsertForm($id)  | 
            ||
| 583 | |||
| 584 | /**  | 
            ||
| 585 | * Get file insert form  | 
            ||
| 586 | *  | 
            ||
| 587 | * @return Form  | 
            ||
| 588 | */  | 
            ||
| 589 | View Code Duplication | public function fileInsertForm()  | 
            |
| 596 | |||
| 597 | /**  | 
            ||
| 598 | * Abstract method for generating a form for a file  | 
            ||
| 599 | *  | 
            ||
| 600 | * @param int $id Record ID  | 
            ||
| 601 | * @param string $name Form name  | 
            ||
| 602 | * @param array $context Form context  | 
            ||
| 603 | * @return Form  | 
            ||
| 604 | */  | 
            ||
| 605 | protected function getAbstractFileForm($id, $name, $context = [])  | 
            ||
| 634 | |||
| 635 | /**  | 
            ||
| 636 | * Get form for selecting a file  | 
            ||
| 637 | *  | 
            ||
| 638 | * @return Form  | 
            ||
| 639 | */  | 
            ||
| 640 | public function fileSelectForm()  | 
            ||
| 647 | |||
| 648 | /**  | 
            ||
| 649 | * Get form for selecting a file  | 
            ||
| 650 | *  | 
            ||
| 651 | * @param int $id ID of the record being selected  | 
            ||
| 652 | * @return Form  | 
            ||
| 653 | */  | 
            ||
| 654 | public function getFileSelectForm($id)  | 
            ||
| 658 | |||
| 659 | /**  | 
            ||
| 660 | * @param array $context  | 
            ||
| 661 | * @return Form  | 
            ||
| 662 | * @throws InvalidArgumentException  | 
            ||
| 663 | */  | 
            ||
| 664 | public function getFileHistoryForm($context)  | 
            ||
| 706 | |||
| 707 | /**  | 
            ||
| 708 | * Gets a JSON schema representing the current edit form.  | 
            ||
| 709 | *  | 
            ||
| 710 | * WARNING: Experimental API.  | 
            ||
| 711 | *  | 
            ||
| 712 | * @param HTTPRequest $request  | 
            ||
| 713 | * @return HTTPResponse  | 
            ||
| 714 | */  | 
            ||
| 715 | public function schema($request)  | 
            ||
| 738 | |||
| 739 | /**  | 
            ||
| 740 | * Get file history form  | 
            ||
| 741 | *  | 
            ||
| 742 | * @return Form  | 
            ||
| 743 | */  | 
            ||
| 744 | public function fileHistoryForm()  | 
            ||
| 755 | |||
| 756 | /**  | 
            ||
| 757 | * @param array $data  | 
            ||
| 758 | * @param Form $form  | 
            ||
| 759 | * @return HTTPResponse  | 
            ||
| 760 | */  | 
            ||
| 761 | public function save($data, $form)  | 
            ||
| 765 | |||
| 766 | /**  | 
            ||
| 767 | * @param array $data  | 
            ||
| 768 | * @param Form $form  | 
            ||
| 769 | * @return HTTPResponse  | 
            ||
| 770 | */  | 
            ||
| 771 | public function publish($data, $form)  | 
            ||
| 775 | |||
| 776 | /**  | 
            ||
| 777 | * Update thisrecord  | 
            ||
| 778 | *  | 
            ||
| 779 | * @param array $data  | 
            ||
| 780 | * @param Form $form  | 
            ||
| 781 | * @param bool $doPublish  | 
            ||
| 782 | * @return HTTPResponse  | 
            ||
| 783 | */  | 
            ||
| 784 | protected function saveOrPublish($data, $form, $doPublish = false)  | 
            ||
| 831 | |||
| 832 | public function unpublish($data, $form)  | 
            ||
| 856 | |||
| 857 | /**  | 
            ||
| 858 | * @param File $file  | 
            ||
| 859 | *  | 
            ||
| 860 | * @return array  | 
            ||
| 861 | */  | 
            ||
| 862 | public function getObjectFromData(File $file)  | 
            ||
| 932 | |||
| 933 | /**  | 
            ||
| 934 | * Action handler for adding pages to a campaign  | 
            ||
| 935 | *  | 
            ||
| 936 | * @param array $data  | 
            ||
| 937 | * @param Form $form  | 
            ||
| 938 | * @return DBHTMLText|HTTPResponse  | 
            ||
| 939 | */  | 
            ||
| 940 | public function addtocampaign($data, $form)  | 
            ||
| 956 | |||
| 957 | /**  | 
            ||
| 958 | * Url handler for add to campaign form  | 
            ||
| 959 | *  | 
            ||
| 960 | * @param HTTPRequest $request  | 
            ||
| 961 | * @return Form  | 
            ||
| 962 | */  | 
            ||
| 963 | public function addToCampaignForm($request)  | 
            ||
| 969 | |||
| 970 | /**  | 
            ||
| 971 | * @param int $id  | 
            ||
| 972 | * @return Form  | 
            ||
| 973 | */  | 
            ||
| 974 | public function getAddToCampaignForm($id)  | 
            ||
| 1008 | |||
| 1009 | /**  | 
            ||
| 1010 | * @return Upload  | 
            ||
| 1011 | */  | 
            ||
| 1012 | protected function getUpload()  | 
            ||
| 1022 | |||
| 1023 | /**  | 
            ||
| 1024 | * Get response for successfully updated record  | 
            ||
| 1025 | *  | 
            ||
| 1026 | * @param File $record  | 
            ||
| 1027 | * @param Form $form  | 
            ||
| 1028 | * @return HTTPResponse  | 
            ||
| 1029 | */  | 
            ||
| 1030 | protected function getRecordUpdatedResponse($record, $form)  | 
            ||
| 1037 | |||
| 1038 | /**  | 
            ||
| 1039 | * Scaffold a search form.  | 
            ||
| 1040 | * Note: This form does not submit to itself, but rather uses the apiReadFolder endpoint  | 
            ||
| 1041 | * (to be replaced with graphql)  | 
            ||
| 1042 | *  | 
            ||
| 1043 | * @return Form  | 
            ||
| 1044 | */  | 
            ||
| 1045 | public function fileSearchForm()  | 
            ||
| 1050 | |||
| 1051 | /**  | 
            ||
| 1052 | * Allow search form to be accessible to schema  | 
            ||
| 1053 | *  | 
            ||
| 1054 | * @return Form  | 
            ||
| 1055 | */  | 
            ||
| 1056 | public function getFileSearchform()  | 
            ||
| 1060 | }  | 
            ||
| 1061 |