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 |
||
48 | class AssetAdmin extends LeftAndMain implements PermissionProvider |
||
49 | { |
||
50 | private static $url_segment = 'assets'; |
||
51 | |||
52 | private static $url_rule = '/$Action/$ID'; |
||
53 | |||
54 | private static $menu_title = 'Files'; |
||
55 | |||
56 | private static $menu_icon_class = 'font-icon-image'; |
||
57 | |||
58 | private static $tree_class = Folder::class; |
||
59 | |||
60 | private static $url_handlers = [ |
||
61 | // Legacy redirect for SS3-style detail view |
||
62 | 'EditForm/field/File/item/$FileID/$Action' => 'legacyRedirectForEditView', |
||
63 | // Pass all URLs to the index, for React to unpack |
||
64 | 'show/$FolderID/edit/$FileID' => 'index', |
||
65 | // API access points with structured data |
||
66 | 'POST api/createFile' => 'apiCreateFile', |
||
67 | 'POST api/uploadFile' => 'apiUploadFile', |
||
68 | 'GET api/history' => 'apiHistory', |
||
69 | 'fileEditForm/$ID' => 'fileEditForm', |
||
70 | 'fileInsertForm/$ID' => 'fileInsertForm', |
||
71 | 'fileEditorLinkForm/$ID' => 'fileEditorLinkForm', |
||
72 | 'fileHistoryForm/$ID/$VersionID' => 'fileHistoryForm', |
||
73 | 'folderCreateForm/$ParentID' => 'folderCreateForm', |
||
74 | 'fileSelectForm/$ID' => 'fileSelectForm', |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Amount of results showing on a single page. |
||
79 | * |
||
80 | * @config |
||
81 | * @var int |
||
82 | */ |
||
83 | private static $page_length = 50; |
||
84 | |||
85 | /** |
||
86 | * @config |
||
87 | * @see Upload->allowedMaxFileSize |
||
88 | * @var int |
||
89 | */ |
||
90 | private static $allowed_max_file_size; |
||
91 | |||
92 | /** |
||
93 | * @config |
||
94 | * |
||
95 | * @var int |
||
96 | */ |
||
97 | private static $max_history_entries = 100; |
||
98 | |||
99 | /** |
||
100 | * @var array |
||
101 | */ |
||
102 | private static $allowed_actions = array( |
||
103 | 'legacyRedirectForEditView', |
||
104 | 'apiCreateFile', |
||
105 | 'apiUploadFile', |
||
106 | 'apiHistory', |
||
107 | 'folderCreateForm', |
||
108 | 'fileEditForm', |
||
109 | 'fileHistoryForm', |
||
110 | 'addToCampaignForm', |
||
111 | 'fileInsertForm', |
||
112 | 'fileEditorLinkForm', |
||
113 | 'schema', |
||
114 | 'fileSelectForm', |
||
115 | 'fileSearchForm', |
||
116 | ); |
||
117 | |||
118 | private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin'; |
||
119 | |||
120 | /** |
||
121 | * Retina thumbnail image (native size: 176) |
||
122 | * |
||
123 | * @config |
||
124 | * @var int |
||
125 | */ |
||
126 | private static $thumbnail_width = 352; |
||
127 | |||
128 | /** |
||
129 | * Retina thumbnail height (native size: 132) |
||
130 | * |
||
131 | * @config |
||
132 | * @var int |
||
133 | */ |
||
134 | private static $thumbnail_height = 264; |
||
135 | |||
136 | /** |
||
137 | * Safely limit max inline thumbnail size to 200kb |
||
138 | * |
||
139 | * @config |
||
140 | * @var int |
||
141 | */ |
||
142 | private static $max_thumbnail_bytes = 200000; |
||
143 | |||
144 | /** |
||
145 | * Set up the controller |
||
146 | */ |
||
147 | public function init() |
||
148 | { |
||
149 | parent::init(); |
||
150 | |||
151 | $module = ModuleLoader::getModule('silverstripe/asset-admin'); |
||
152 | Requirements::add_i18n_javascript($module->getResourcePath('client/lang'), false, true); |
||
153 | Requirements::javascript($module->getResourcePath("client/dist/js/bundle.js")); |
||
154 | Requirements::css($module->getResourcePath("client/dist/styles/bundle.css")); |
||
155 | |||
156 | CMSBatchActionHandler::register('delete', DeleteAssets::class, Folder::class); |
||
157 | } |
||
158 | |||
159 | public function getClientConfig() |
||
160 | { |
||
161 | $baseLink = $this->Link(); |
||
162 | return array_merge(parent::getClientConfig(), [ |
||
163 | 'reactRouter' => true, |
||
164 | 'createFileEndpoint' => [ |
||
165 | 'url' => Controller::join_links($baseLink, 'api/createFile'), |
||
166 | 'method' => 'post', |
||
167 | 'payloadFormat' => 'urlencoded', |
||
168 | ], |
||
169 | 'uploadFileEndpoint' => [ |
||
170 | 'url' => Controller::join_links($baseLink, 'api/uploadFile'), |
||
171 | 'method' => 'post', |
||
172 | 'payloadFormat' => 'urlencoded', |
||
173 | ], |
||
174 | 'historyEndpoint' => [ |
||
175 | 'url' => Controller::join_links($baseLink, 'api/history'), |
||
176 | 'method' => 'get', |
||
177 | 'responseFormat' => 'json', |
||
178 | ], |
||
179 | 'limit' => $this->config()->page_length, |
||
180 | 'form' => [ |
||
181 | 'fileEditForm' => [ |
||
182 | 'schemaUrl' => $this->Link('schema/fileEditForm') |
||
183 | ], |
||
184 | 'fileInsertForm' => [ |
||
185 | 'schemaUrl' => $this->Link('schema/fileInsertForm') |
||
186 | ], |
||
187 | 'remoteEditForm' => [ |
||
188 | 'schemaUrl' => LeftAndMain::singleton() |
||
189 | ->Link('Modals/remoteEditFormSchema'), |
||
190 | ], |
||
191 | 'remoteCreateForm' => [ |
||
192 | 'schemaUrl' => LeftAndMain::singleton() |
||
193 | ->Link('methodSchema/Modals/remoteCreateForm') |
||
194 | ], |
||
195 | 'fileSelectForm' => [ |
||
196 | 'schemaUrl' => $this->Link('schema/fileSelectForm') |
||
197 | ], |
||
198 | 'addToCampaignForm' => [ |
||
199 | 'schemaUrl' => $this->Link('schema/addToCampaignForm') |
||
200 | ], |
||
201 | 'fileHistoryForm' => [ |
||
202 | 'schemaUrl' => $this->Link('schema/fileHistoryForm') |
||
203 | ], |
||
204 | 'fileSearchForm' => [ |
||
205 | 'schemaUrl' => $this->Link('schema/fileSearchForm') |
||
206 | ], |
||
207 | 'folderCreateForm' => [ |
||
208 | 'schemaUrl' => $this->Link('schema/folderCreateForm') |
||
209 | ], |
||
210 | 'fileEditorLinkForm' => [ |
||
211 | 'schemaUrl' => $this->Link('schema/fileEditorLinkForm'), |
||
212 | ], |
||
213 | ], |
||
214 | ]); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Creates a single file based on a form-urlencoded upload. |
||
219 | * |
||
220 | * @param HTTPRequest $request |
||
221 | * @return HTTPRequest|HTTPResponse |
||
222 | */ |
||
223 | public function apiCreateFile(HTTPRequest $request) |
||
224 | { |
||
225 | $data = $request->postVars(); |
||
226 | |||
227 | // When creating new files, rename on conflict |
||
228 | $upload = $this->getUpload(); |
||
229 | $upload->setReplaceFile(false); |
||
230 | |||
231 | // CSRF check |
||
232 | $token = SecurityToken::inst(); |
||
233 | View Code Duplication | if (empty($data[$token->getName()]) || !$token->check($data[$token->getName()])) { |
|
234 | return new HTTPResponse(null, 400); |
||
235 | } |
||
236 | |||
237 | // Check parent record |
||
238 | /** @var Folder $parentRecord */ |
||
239 | $parentRecord = null; |
||
240 | if (!empty($data['ParentID']) && is_numeric($data['ParentID'])) { |
||
241 | $parentRecord = Folder::get()->byID($data['ParentID']); |
||
242 | } |
||
243 | $data['Parent'] = $parentRecord; |
||
244 | |||
245 | $tmpFile = $request->postVar('Upload'); |
||
246 | View Code Duplication | if (!$upload->validate($tmpFile)) { |
|
247 | $result = ['message' => null]; |
||
248 | $errors = $upload->getErrors(); |
||
249 | if ($message = array_shift($errors)) { |
||
250 | $result['message'] = [ |
||
251 | 'type' => 'error', |
||
252 | 'value' => $message, |
||
253 | ]; |
||
254 | } |
||
255 | return (new HTTPResponse(json_encode($result), 400)) |
||
256 | ->addHeader('Content-Type', 'application/json'); |
||
257 | } |
||
258 | |||
259 | // TODO Allow batch uploads |
||
260 | $fileClass = File::get_class_for_file_extension(File::get_file_extension($tmpFile['name'])); |
||
261 | /** @var File $file */ |
||
262 | $file = Injector::inst()->create($fileClass); |
||
263 | |||
264 | // check canCreate permissions |
||
265 | View Code Duplication | if (!$file->canCreate(null, $data)) { |
|
266 | $result = ['message' => [ |
||
267 | 'type' => 'error', |
||
268 | 'value' => _t( |
||
269 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied', |
||
270 | 'You do not have permission to add files' |
||
271 | ) |
||
272 | ]]; |
||
273 | return (new HTTPResponse(json_encode($result), 403)) |
||
274 | ->addHeader('Content-Type', 'application/json'); |
||
275 | } |
||
276 | |||
277 | $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
||
278 | View Code Duplication | if (!$uploadResult) { |
|
279 | $result = ['message' => [ |
||
280 | 'type' => 'error', |
||
281 | 'value' => _t( |
||
282 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed', |
||
283 | 'Failed to load file' |
||
284 | ) |
||
285 | ]]; |
||
286 | return (new HTTPResponse(json_encode($result), 400)) |
||
287 | ->addHeader('Content-Type', 'application/json'); |
||
288 | } |
||
289 | |||
290 | $file->ParentID = $parentRecord ? $parentRecord->ID : 0; |
||
291 | $file->write(); |
||
292 | |||
293 | $result = [$this->getObjectFromData($file)]; |
||
294 | |||
295 | // Don't discard pre-generated client side canvas thumbnail |
||
296 | if ($result[0]['category'] === 'image') { |
||
297 | unset($result[0]['thumbnail']); |
||
298 | } |
||
299 | |||
300 | return (new HTTPResponse(json_encode($result))) |
||
301 | ->addHeader('Content-Type', 'application/json'); |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Upload a new asset for a pre-existing record. Returns the asset tuple. |
||
306 | * |
||
307 | * Note that conflict resolution is as follows: |
||
308 | * - If uploading a file with the same extension, we simply keep the same filename, |
||
309 | * and overwrite any existing files (same name + sha = don't duplicate). |
||
310 | * - If uploading a new file with a different extension, then the filename will |
||
311 | * be replaced, and will be checked for uniqueness against other File dataobjects. |
||
312 | * |
||
313 | * @param HTTPRequest $request Request containing vars 'ID' of parent record ID, |
||
314 | * and 'Name' as form filename value |
||
315 | * @return HTTPRequest|HTTPResponse |
||
316 | */ |
||
317 | public function apiUploadFile(HTTPRequest $request) |
||
318 | { |
||
319 | $data = $request->postVars(); |
||
320 | |||
321 | // When updating files, replace on conflict |
||
322 | $upload = $this->getUpload(); |
||
323 | $upload->setReplaceFile(true); |
||
324 | |||
325 | // CSRF check |
||
326 | $token = SecurityToken::inst(); |
||
327 | View Code Duplication | if (empty($data[$token->getName()]) || !$token->check($data[$token->getName()])) { |
|
328 | return new HTTPResponse(null, 400); |
||
329 | } |
||
330 | $tmpFile = $data['Upload']; |
||
331 | if (empty($data['ID']) || empty($tmpFile['name']) || !array_key_exists('Name', $data)) { |
||
332 | return new HTTPResponse('Invalid request', 400); |
||
333 | } |
||
334 | |||
335 | // Check parent record |
||
336 | /** @var File $file */ |
||
337 | $file = File::get()->byID($data['ID']); |
||
338 | if (!$file) { |
||
339 | return new HTTPResponse('File not found', 404); |
||
340 | } |
||
341 | $folder = $file->ParentID ? $file->Parent()->getFilename() : '/'; |
||
342 | |||
343 | // If extension is the same, attempt to re-use existing name |
||
344 | if (File::get_file_extension($tmpFile['name']) === File::get_file_extension($data['Name'])) { |
||
345 | $tmpFile['name'] = $data['Name']; |
||
346 | } else { |
||
347 | // If we are allowing this upload to rename the underlying record, |
||
348 | // do a uniqueness check. |
||
349 | $renamer = $this->getNameGenerator($tmpFile['name']); |
||
350 | foreach ($renamer as $name) { |
||
351 | $filename = File::join_paths($folder, $name); |
||
352 | if (!File::find($filename)) { |
||
353 | $tmpFile['name'] = $name; |
||
354 | break; |
||
355 | } |
||
356 | } |
||
357 | } |
||
358 | |||
359 | View Code Duplication | if (!$upload->validate($tmpFile)) { |
|
360 | $result = ['message' => null]; |
||
361 | $errors = $upload->getErrors(); |
||
362 | if ($message = array_shift($errors)) { |
||
363 | $result['message'] = [ |
||
364 | 'type' => 'error', |
||
365 | 'value' => $message, |
||
366 | ]; |
||
367 | } |
||
368 | return (new HTTPResponse(json_encode($result), 400)) |
||
369 | ->addHeader('Content-Type', 'application/json'); |
||
370 | } |
||
371 | |||
372 | try { |
||
373 | $tuple = $upload->load($tmpFile, $folder); |
||
374 | } catch (Exception $e) { |
||
375 | $result = [ |
||
376 | 'message' => [ |
||
377 | 'type' => 'error', |
||
378 | 'value' => $e->getMessage(), |
||
379 | ] |
||
380 | ]; |
||
381 | return (new HTTPResponse(json_encode($result), 400)) |
||
382 | ->addHeader('Content-Type', 'application/json'); |
||
383 | } |
||
384 | |||
385 | if ($upload->isError()) { |
||
386 | $result['message'] = [ |
||
387 | 'type' => 'error', |
||
388 | 'value' => implode(' ' . PHP_EOL, $upload->getErrors()), |
||
389 | ]; |
||
390 | return (new HTTPResponse(json_encode($result), 400)) |
||
391 | ->addHeader('Content-Type', 'application/json'); |
||
392 | } |
||
393 | |||
394 | $tuple['Name'] = basename($tuple['Filename']); |
||
395 | return (new HTTPResponse(json_encode($tuple))) |
||
396 | ->addHeader('Content-Type', 'application/json'); |
||
397 | } |
||
398 | |||
399 | /** |
||
400 | * Returns a JSON array for history of a given file ID. Returns a list of all the history. |
||
401 | * |
||
402 | * @param HTTPRequest $request |
||
403 | * @return HTTPResponse |
||
404 | */ |
||
405 | public function apiHistory(HTTPRequest $request) |
||
406 | { |
||
407 | // CSRF check not required as the GET request has no side effects. |
||
408 | $fileId = $request->getVar('fileId'); |
||
409 | |||
410 | if (!$fileId || !is_numeric($fileId)) { |
||
411 | return new HTTPResponse(null, 400); |
||
412 | } |
||
413 | |||
414 | $class = File::class; |
||
415 | $file = DataObject::get($class)->byID($fileId); |
||
416 | |||
417 | if (!$file) { |
||
418 | return new HTTPResponse(null, 404); |
||
419 | } |
||
420 | |||
421 | if (!$file->canView()) { |
||
422 | return new HTTPResponse(null, 403); |
||
423 | } |
||
424 | |||
425 | $versions = Versioned::get_all_versions($class, $fileId) |
||
426 | ->limit($this->config()->max_history_entries) |
||
427 | ->sort('Version', 'DESC'); |
||
428 | |||
429 | $output = array(); |
||
430 | $next = array(); |
||
431 | $prev = null; |
||
432 | |||
433 | // swap the order so we can get the version number to compare against. |
||
434 | // i.e version 3 needs to know version 2 is the previous version |
||
435 | $copy = $versions->map('Version', 'Version')->toArray(); |
||
436 | foreach (array_reverse($copy) as $k => $v) { |
||
437 | if ($prev) { |
||
438 | $next[$v] = $prev; |
||
439 | } |
||
440 | |||
441 | $prev = $v; |
||
442 | } |
||
443 | |||
444 | $_cachedMembers = array(); |
||
445 | |||
446 | /** @var File|AssetAdminFile $version */ |
||
447 | foreach ($versions as $version) { |
||
448 | $author = null; |
||
449 | |||
450 | if ($version->AuthorID) { |
||
451 | if (!isset($_cachedMembers[$version->AuthorID])) { |
||
452 | $_cachedMembers[$version->AuthorID] = DataObject::get(Member::class) |
||
453 | ->byID($version->AuthorID); |
||
454 | } |
||
455 | |||
456 | $author = $_cachedMembers[$version->AuthorID]; |
||
457 | } |
||
458 | |||
459 | if ($version->canView()) { |
||
460 | if (isset($next[$version->Version])) { |
||
461 | $summary = $version->humanizedChanges( |
||
462 | $version->Version, |
||
463 | $next[$version->Version] |
||
464 | ); |
||
465 | |||
466 | // if no summary returned by humanizedChanges, i.e we cannot work out what changed, just show a |
||
467 | // generic message |
||
468 | if (!$summary) { |
||
469 | $summary = _t(__CLASS__.'.SAVEDFILE', "Saved file"); |
||
470 | } |
||
471 | } else { |
||
472 | $summary = _t(__CLASS__.'.UPLOADEDFILE', "Uploaded file"); |
||
473 | } |
||
474 | |||
475 | $output[] = array( |
||
476 | 'versionid' => $version->Version, |
||
477 | 'date_ago' => $version->dbObject('LastEdited')->Ago(), |
||
478 | 'date_formatted' => $version->dbObject('LastEdited')->Nice(), |
||
479 | 'status' => ($version->WasPublished) ? _t(__CLASS__.'.PUBLISHED', 'Published') : '', |
||
480 | 'author' => ($author) |
||
481 | ? $author->Name |
||
482 | : _t(__CLASS__.'.UNKNOWN', "Unknown"), |
||
483 | 'summary' => ($summary) |
||
484 | ? $summary |
||
485 | : _t(__CLASS__.'.NOSUMMARY', "No summary available") |
||
486 | ); |
||
487 | } |
||
488 | } |
||
489 | |||
490 | return |
||
491 | (new HTTPResponse(json_encode($output)))->addHeader('Content-Type', 'application/json'); |
||
492 | } |
||
493 | |||
494 | /** |
||
495 | * Redirects 3.x style detail links to new 4.x style routing. |
||
496 | * |
||
497 | * @param HTTPRequest $request |
||
498 | */ |
||
499 | public function legacyRedirectForEditView($request) |
||
500 | { |
||
501 | $fileID = $request->param('FileID'); |
||
502 | /** @var File $file */ |
||
503 | $file = File::get()->byID($fileID); |
||
504 | $link = $this->getFileEditLink($file) ?: $this->Link(); |
||
505 | $this->redirect($link); |
||
506 | } |
||
507 | |||
508 | /** |
||
509 | * Given a file return the CMS link to edit it |
||
510 | * |
||
511 | * @param File $file |
||
512 | * @return string |
||
513 | */ |
||
514 | public function getFileEditLink($file) |
||
515 | { |
||
516 | if (!$file || !$file->isInDB()) { |
||
517 | return null; |
||
518 | } |
||
519 | |||
520 | return Controller::join_links( |
||
521 | $this->Link('show'), |
||
522 | $file->ParentID, |
||
523 | 'edit', |
||
524 | $file->ID |
||
525 | ); |
||
526 | } |
||
527 | |||
528 | /** |
||
529 | * Get an asset renamer for the given filename. |
||
530 | * |
||
531 | * @param string $filename Path name |
||
532 | * @return AssetNameGenerator |
||
533 | */ |
||
534 | protected function getNameGenerator($filename) |
||
539 | |||
540 | /** |
||
541 | * @todo Implement on client |
||
542 | * |
||
543 | * @param bool $unlinked |
||
544 | * @return ArrayList |
||
545 | */ |
||
546 | public function breadcrumbs($unlinked = false) |
||
550 | |||
551 | |||
552 | /** |
||
553 | * Don't include class namespace in auto-generated CSS class |
||
554 | */ |
||
555 | public function baseCSSClasses() |
||
559 | |||
560 | public function providePermissions() |
||
561 | { |
||
562 | return array( |
||
563 | "CMS_ACCESS_AssetAdmin" => array( |
||
564 | 'name' => _t('SilverStripe\\CMS\\Controllers\\CMSMain.ACCESS', "Access to '{title}' section", array( |
||
565 | 'title' => static::menu_title() |
||
566 | )), |
||
567 | 'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access') |
||
568 | ) |
||
569 | ); |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * Build a form scaffolder for this model |
||
574 | * |
||
575 | * NOTE: Volatile api. May be moved to {@see LeftAndMain} |
||
576 | * |
||
577 | * @param File $file |
||
578 | * @return FormFactory |
||
579 | */ |
||
580 | public function getFormFactory(File $file) |
||
593 | |||
594 | /** |
||
595 | * The form is used to generate a form schema, |
||
596 | * as well as an intermediary object to process data through API endpoints. |
||
597 | * Since it's used directly on API endpoints, it does not have any form actions. |
||
598 | * It handles both {@link File} and {@link Folder} records. |
||
599 | * |
||
600 | * @param int $id |
||
601 | * @return Form |
||
602 | */ |
||
603 | public function getFileEditForm($id) |
||
607 | |||
608 | /** |
||
609 | * Get file edit form |
||
610 | * |
||
611 | * @param HTTPRequest $request |
||
612 | * @return Form |
||
613 | */ |
||
614 | View Code Duplication | public function fileEditForm($request = null) |
|
628 | |||
629 | /** |
||
630 | * The form is used to generate a form schema, |
||
631 | * as well as an intermediary object to process data through API endpoints. |
||
632 | * Since it's used directly on API endpoints, it does not have any form actions. |
||
633 | * It handles both {@link File} and {@link Folder} records. |
||
634 | * |
||
635 | * @param int $id |
||
636 | * @return Form |
||
637 | */ |
||
638 | public function getFileInsertForm($id) |
||
642 | |||
643 | /** |
||
644 | * Get file insert media form |
||
645 | * |
||
646 | * @param HTTPRequest $request |
||
647 | * @return Form |
||
648 | */ |
||
649 | View Code Duplication | public function fileInsertForm($request = null) |
|
663 | |||
664 | /** |
||
665 | * The form used to generate a form schema, since it's used directly on API endpoints, |
||
666 | * it does not have any form actions. |
||
667 | * |
||
668 | * @param $id |
||
669 | * @return Form |
||
670 | */ |
||
671 | public function getFileEditorLinkForm($id) |
||
675 | |||
676 | /** |
||
677 | * Get the file insert link form |
||
678 | * |
||
679 | * @param HTTPRequest $request |
||
680 | * @return Form |
||
681 | */ |
||
682 | View Code Duplication | public function fileEditorLinkForm($request = null) |
|
696 | |||
697 | /** |
||
698 | * Abstract method for generating a form for a file |
||
699 | * |
||
700 | * @param int $id Record ID |
||
701 | * @param string $name Form name |
||
702 | * @param array $context Form context |
||
703 | * @return Form |
||
704 | */ |
||
705 | protected function getAbstractFileForm($id, $name, $context = []) |
||
744 | |||
745 | /** |
||
746 | * Get form for selecting a file |
||
747 | * |
||
748 | * @return Form |
||
749 | */ |
||
750 | public function fileSelectForm() |
||
757 | |||
758 | /** |
||
759 | * Get form for selecting a file |
||
760 | * |
||
761 | * @param int $id ID of the record being selected |
||
762 | * @return Form |
||
763 | */ |
||
764 | public function getFileSelectForm($id) |
||
768 | |||
769 | /** |
||
770 | * @param array $context |
||
771 | * @return Form |
||
772 | * @throws InvalidArgumentException |
||
773 | */ |
||
774 | public function getFileHistoryForm($context) |
||
821 | |||
822 | /** |
||
823 | * Gets a JSON schema representing the current edit form. |
||
824 | * |
||
825 | * WARNING: Experimental API. |
||
826 | * |
||
827 | * @param HTTPRequest $request |
||
828 | * @return HTTPResponse |
||
829 | */ |
||
830 | public function schema($request) |
||
853 | |||
854 | /** |
||
855 | * Get file history form |
||
856 | * |
||
857 | * @param HTTPRequest $request |
||
858 | * @return Form |
||
859 | */ |
||
860 | public function fileHistoryForm($request = null) |
||
883 | |||
884 | /** |
||
885 | * @param array $data |
||
886 | * @param Form $form |
||
887 | * @return HTTPResponse |
||
888 | */ |
||
889 | public function createfolder($data, $form) |
||
924 | |||
925 | /** |
||
926 | * @param array $data |
||
927 | * @param Form $form |
||
928 | * @return HTTPResponse |
||
929 | */ |
||
930 | public function save($data, $form) |
||
934 | |||
935 | /** |
||
936 | * @param array $data |
||
937 | * @param Form $form |
||
938 | * @return HTTPResponse |
||
939 | */ |
||
940 | public function publish($data, $form) |
||
944 | |||
945 | /** |
||
946 | * Update thisrecord |
||
947 | * |
||
948 | * @param array $data |
||
949 | * @param Form $form |
||
950 | * @param bool $doPublish |
||
951 | * @return HTTPResponse |
||
952 | */ |
||
953 | protected function saveOrPublish($data, $form, $doPublish = false) |
||
1002 | |||
1003 | public function unpublish($data, $form) |
||
1027 | |||
1028 | /** |
||
1029 | * @param File $file |
||
1030 | * |
||
1031 | * @return array |
||
1032 | */ |
||
1033 | public function getObjectFromData(File $file) |
||
1103 | |||
1104 | /** |
||
1105 | * Action handler for adding pages to a campaign |
||
1106 | * |
||
1107 | * @param array $data |
||
1108 | * @param Form $form |
||
1109 | * @return DBHTMLText|HTTPResponse |
||
1110 | */ |
||
1111 | public function addtocampaign($data, $form) |
||
1127 | |||
1128 | /** |
||
1129 | * Url handler for add to campaign form |
||
1130 | * |
||
1131 | * @param HTTPRequest $request |
||
1132 | * @return Form |
||
1133 | */ |
||
1134 | public function addToCampaignForm($request) |
||
1140 | |||
1141 | /** |
||
1142 | * @param int $id |
||
1143 | * @return Form |
||
1144 | */ |
||
1145 | public function getAddToCampaignForm($id) |
||
1179 | |||
1180 | /** |
||
1181 | * @return Upload |
||
1182 | */ |
||
1183 | protected function getUpload() |
||
1193 | |||
1194 | /** |
||
1195 | * Get response for successfully updated record |
||
1196 | * |
||
1197 | * @param File $record |
||
1198 | * @param Form $form |
||
1199 | * @return HTTPResponse |
||
1200 | */ |
||
1201 | protected function getRecordUpdatedResponse($record, $form) |
||
1208 | |||
1209 | /** |
||
1210 | * @param HTTPRequest $request |
||
1211 | * @return Form |
||
1212 | */ |
||
1213 | public function folderCreateForm($request = null) |
||
1228 | |||
1229 | /** |
||
1230 | * Returns the form to be used for creating a new folder |
||
1231 | * @param $parentId |
||
1232 | * @return Form |
||
1233 | */ |
||
1234 | public function getFolderCreateForm($parentId = 0) |
||
1247 | |||
1248 | /** |
||
1249 | * Scaffold a search form. |
||
1250 | * Note: This form does not submit to itself, but rather uses the apiReadFolder endpoint |
||
1251 | * (to be replaced with graphql) |
||
1252 | * |
||
1253 | * @return Form |
||
1254 | */ |
||
1255 | public function fileSearchForm() |
||
1260 | |||
1261 | /** |
||
1262 | * Allow search form to be accessible to schema |
||
1263 | * |
||
1264 | * @return Form |
||
1265 | */ |
||
1266 | public function getFileSearchform() |
||
1270 | } |
||
1271 |