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 | ||
| 47 | class AssetAdmin extends LeftAndMain implements PermissionProvider | ||
| 48 | { | ||
| 49 | private static $url_segment = 'assets'; | ||
| 50 | |||
| 51 | private static $url_rule = '/$Action/$ID'; | ||
| 52 | |||
| 53 | private static $menu_title = 'Files'; | ||
| 54 | |||
| 55 | private static $menu_icon_class = 'font-icon-image'; | ||
| 56 | |||
| 57 | private static $tree_class = 'SilverStripe\\Assets\\Folder'; | ||
| 58 | |||
| 59 | private static $url_handlers = [ | ||
| 60 | // Legacy redirect for SS3-style detail view | ||
| 61 | 'EditForm/field/File/item/$FileID/$Action' => 'legacyRedirectForEditView', | ||
| 62 | // Pass all URLs to the index, for React to unpack | ||
| 63 | 'show/$FolderID/edit/$FileID' => 'index', | ||
| 64 | // API access points with structured data | ||
| 65 | 'POST api/createFile' => 'apiCreateFile', | ||
| 66 | 'POST api/uploadFile' => 'apiUploadFile', | ||
| 67 | 'GET api/history' => 'apiHistory', | ||
| 68 | // for validating before generating the schema | ||
| 69 | 'schemaWithValidate/$FormName' => 'schemaWithValidate' | ||
| 70 | ]; | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Amount of results showing on a single page. | ||
| 74 | * | ||
| 75 | * @config | ||
| 76 | * @var int | ||
| 77 | */ | ||
| 78 | private static $page_length = 15; | ||
| 79 | |||
| 80 | /** | ||
| 81 | * @config | ||
| 82 | * @see Upload->allowedMaxFileSize | ||
| 83 | * @var int | ||
| 84 | */ | ||
| 85 | private static $allowed_max_file_size; | ||
| 86 | |||
| 87 | /** | ||
| 88 | * @config | ||
| 89 | * | ||
| 90 | * @var int | ||
| 91 | */ | ||
| 92 | private static $max_history_entries = 100; | ||
| 93 | |||
| 94 | /** | ||
| 95 | * @var array | ||
| 96 | */ | ||
| 97 | private static $allowed_actions = array( | ||
| 98 | 'legacyRedirectForEditView', | ||
| 99 | 'apiCreateFile', | ||
| 100 | 'apiUploadFile', | ||
| 101 | 'apiHistory', | ||
| 102 | 'fileEditForm', | ||
| 103 | 'fileHistoryForm', | ||
| 104 | 'addToCampaignForm', | ||
| 105 | 'fileInsertForm', | ||
| 106 | 'remoteEditForm', | ||
| 107 | 'remoteCreateForm', | ||
| 108 | 'schema', | ||
| 109 | 'fileSelectForm', | ||
| 110 | 'fileSearchForm', | ||
| 111 | 'schemaWithValidate', | ||
| 112 | ); | ||
| 113 | |||
| 114 | private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin'; | ||
| 115 | |||
| 116 | private static $thumbnail_width = 400; | ||
| 117 | |||
| 118 | private static $thumbnail_height = 300; | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Set up the controller | ||
| 122 | */ | ||
| 123 | public function init() | ||
| 124 |     { | ||
| 125 | parent::init(); | ||
| 126 | |||
| 127 | Requirements::add_i18n_javascript(ASSET_ADMIN_DIR . '/client/lang', false, true); | ||
| 128 | Requirements::javascript(ASSET_ADMIN_DIR . "/client/dist/js/bundle.js"); | ||
| 129 | Requirements::css(ASSET_ADMIN_DIR . "/client/dist/styles/bundle.css"); | ||
| 130 | |||
| 131 |         CMSBatchActionHandler::register('delete', DeleteAssets::class, Folder::class); | ||
| 132 | } | ||
| 133 | |||
| 134 | public function getClientConfig() | ||
| 135 |     { | ||
| 136 | $baseLink = $this->Link(); | ||
| 137 | return array_merge(parent::getClientConfig(), [ | ||
| 138 | 'reactRouter' => true, | ||
| 139 | 'createFileEndpoint' => [ | ||
| 140 | 'url' => Controller::join_links($baseLink, 'api/createFile'), | ||
| 141 | 'method' => 'post', | ||
| 142 | 'payloadFormat' => 'urlencoded', | ||
| 143 | ], | ||
| 144 | 'uploadFileEndpoint' => [ | ||
| 145 | 'url' => Controller::join_links($baseLink, 'api/uploadFile'), | ||
| 146 | 'method' => 'post', | ||
| 147 | 'payloadFormat' => 'urlencoded', | ||
| 148 | ], | ||
| 149 | 'historyEndpoint' => [ | ||
| 150 | 'url' => Controller::join_links($baseLink, 'api/history'), | ||
| 151 | 'method' => 'get', | ||
| 152 | 'responseFormat' => 'json', | ||
| 153 | ], | ||
| 154 | 'limit' => $this->config()->page_length, | ||
| 155 | 'form' => [ | ||
| 156 | 'fileEditForm' => [ | ||
| 157 |                     'schemaUrl' => $this->Link('schema/fileEditForm') | ||
| 158 | ], | ||
| 159 | 'fileInsertForm' => [ | ||
| 160 |                     'schemaUrl' => $this->Link('schema/fileInsertForm') | ||
| 161 | ], | ||
| 162 | 'remoteEditForm' => [ | ||
| 163 |                     'schemaUrl' => $this->Link('schemaWithValidate/remoteEditForm') | ||
| 164 | ], | ||
| 165 | 'remoteCreateForm' => [ | ||
| 166 |                     'schemaUrl' => $this->Link('schema/remoteCreateForm') | ||
| 167 | ], | ||
| 168 | 'fileSelectForm' => [ | ||
| 169 |                     'schemaUrl' => $this->Link('schema/fileSelectForm') | ||
| 170 | ], | ||
| 171 | 'addToCampaignForm' => [ | ||
| 172 |                     'schemaUrl' => $this->Link('schema/addToCampaignForm') | ||
| 173 | ], | ||
| 174 | 'fileHistoryForm' => [ | ||
| 175 |                     'schemaUrl' => $this->Link('schema/fileHistoryForm') | ||
| 176 | ], | ||
| 177 | 'fileSearchForm' => [ | ||
| 178 |                     'schemaUrl' => $this->Link('schema/fileSearchForm') | ||
| 179 | ], | ||
| 180 | ], | ||
| 181 | ]); | ||
| 182 | } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Creates a single file based on a form-urlencoded upload. | ||
| 186 | * | ||
| 187 | * @param HTTPRequest $request | ||
| 188 | * @return HTTPRequest|HTTPResponse | ||
| 189 | */ | ||
| 190 | public function apiCreateFile(HTTPRequest $request) | ||
| 191 |     { | ||
| 192 | $data = $request->postVars(); | ||
| 193 | |||
| 194 | // When creating new files, rename on conflict | ||
| 195 | $upload = $this->getUpload(); | ||
| 196 | $upload->setReplaceFile(false); | ||
| 197 | |||
| 198 | // CSRF check | ||
| 199 | $token = SecurityToken::inst(); | ||
| 200 | View Code Duplication |         if (empty($data[$token->getName()]) || !$token->check($data[$token->getName()])) { | |
| 201 | return new HTTPResponse(null, 400); | ||
| 202 | } | ||
| 203 | |||
| 204 | // Check parent record | ||
| 205 | /** @var Folder $parentRecord */ | ||
| 206 | $parentRecord = null; | ||
| 207 |         if (!empty($data['ParentID']) && is_numeric($data['ParentID'])) { | ||
| 208 | $parentRecord = Folder::get()->byID($data['ParentID']); | ||
| 209 | } | ||
| 210 | $data['Parent'] = $parentRecord; | ||
| 211 | |||
| 212 |         $tmpFile = $request->postVar('Upload'); | ||
| 213 | View Code Duplication |         if (!$upload->validate($tmpFile)) { | |
| 214 | $result = ['message' => null]; | ||
| 215 | $errors = $upload->getErrors(); | ||
| 216 |             if ($message = array_shift($errors)) { | ||
| 217 | $result['message'] = [ | ||
| 218 | 'type' => 'error', | ||
| 219 | 'value' => $message, | ||
| 220 | ]; | ||
| 221 | } | ||
| 222 | return (new HTTPResponse(json_encode($result), 400)) | ||
| 223 |                 ->addHeader('Content-Type', 'application/json'); | ||
| 224 | } | ||
| 225 | |||
| 226 | // TODO Allow batch uploads | ||
| 227 | $fileClass = File::get_class_for_file_extension(File::get_file_extension($tmpFile['name'])); | ||
| 228 | /** @var File $file */ | ||
| 229 | $file = Injector::inst()->create($fileClass); | ||
| 230 | |||
| 231 | // check canCreate permissions | ||
| 232 | View Code Duplication |         if (!$file->canCreate(null, $data)) { | |
| 233 | $result = ['message' => [ | ||
| 234 | 'type' => 'error', | ||
| 235 | 'value' => _t( | ||
| 236 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied', | ||
| 237 | 'You do not have permission to add files' | ||
| 238 | ) | ||
| 239 | ]]; | ||
| 240 | return (new HTTPResponse(json_encode($result), 403)) | ||
| 241 |                 ->addHeader('Content-Type', 'application/json'); | ||
| 242 | } | ||
| 243 | |||
| 244 | $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); | ||
| 245 | View Code Duplication |         if (!$uploadResult) { | |
| 246 | $result = ['message' => [ | ||
| 247 | 'type' => 'error', | ||
| 248 | 'value' => _t( | ||
| 249 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed', | ||
| 250 | 'Failed to load file' | ||
| 251 | ) | ||
| 252 | ]]; | ||
| 253 | return (new HTTPResponse(json_encode($result), 400)) | ||
| 254 |                 ->addHeader('Content-Type', 'application/json'); | ||
| 255 | } | ||
| 256 | |||
| 257 | $file->ParentID = $parentRecord ? $parentRecord->ID : 0; | ||
| 258 | $file->write(); | ||
| 259 | |||
| 260 | $result = [$this->getObjectFromData($file)]; | ||
| 261 | |||
| 262 | return (new HTTPResponse(json_encode($result))) | ||
| 263 |             ->addHeader('Content-Type', 'application/json'); | ||
| 264 | } | ||
| 265 | |||
| 266 | /** | ||
| 267 | * Upload a new asset for a pre-existing record. Returns the asset tuple. | ||
| 268 | * | ||
| 269 | * Note that conflict resolution is as follows: | ||
| 270 | * - If uploading a file with the same extension, we simply keep the same filename, | ||
| 271 | * and overwrite any existing files (same name + sha = don't duplicate). | ||
| 272 | * - If uploading a new file with a different extension, then the filename will | ||
| 273 | * be replaced, and will be checked for uniqueness against other File dataobjects. | ||
| 274 | * | ||
| 275 | * @param HTTPRequest $request Request containing vars 'ID' of parent record ID, | ||
| 276 | * and 'Name' as form filename value | ||
| 277 | * @return HTTPRequest|HTTPResponse | ||
| 278 | */ | ||
| 279 | public function apiUploadFile(HTTPRequest $request) | ||
| 280 |     { | ||
| 281 | $data = $request->postVars(); | ||
| 282 | |||
| 283 | // When updating files, replace on conflict | ||
| 284 | $upload = $this->getUpload(); | ||
| 285 | $upload->setReplaceFile(true); | ||
| 286 | |||
| 287 | // CSRF check | ||
| 288 | $token = SecurityToken::inst(); | ||
| 289 | View Code Duplication |         if (empty($data[$token->getName()]) || !$token->check($data[$token->getName()])) { | |
| 290 | return new HTTPResponse(null, 400); | ||
| 291 | } | ||
| 292 | $tmpFile = $data['Upload']; | ||
| 293 |         if (empty($data['ID']) || empty($tmpFile['name']) || !array_key_exists('Name', $data)) { | ||
| 294 |             return new HTTPResponse('Invalid request', 400); | ||
| 295 | } | ||
| 296 | |||
| 297 | // Check parent record | ||
| 298 | /** @var File $file */ | ||
| 299 | $file = File::get()->byID($data['ID']); | ||
| 300 |         if (!$file) { | ||
| 301 |             return new HTTPResponse('File not found', 404); | ||
| 302 | } | ||
| 303 | $folder = $file->ParentID ? $file->Parent()->getFilename() : '/'; | ||
| 304 | |||
| 305 | // If extension is the same, attempt to re-use existing name | ||
| 306 |         if (File::get_file_extension($tmpFile['name']) === File::get_file_extension($data['Name'])) { | ||
| 307 | $tmpFile['name'] = $data['Name']; | ||
| 308 |         } else { | ||
| 309 | // If we are allowing this upload to rename the underlying record, | ||
| 310 | // do a uniqueness check. | ||
| 311 | $renamer = $this->getNameGenerator($tmpFile['name']); | ||
| 312 |             foreach ($renamer as $name) { | ||
| 313 | $filename = File::join_paths($folder, $name); | ||
| 314 |                 if (!File::find($filename)) { | ||
| 315 | $tmpFile['name'] = $name; | ||
| 316 | break; | ||
| 317 | } | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | View Code Duplication |         if (!$upload->validate($tmpFile)) { | |
| 322 | $result = ['message' => null]; | ||
| 323 | $errors = $upload->getErrors(); | ||
| 324 |             if ($message = array_shift($errors)) { | ||
| 325 | $result['message'] = [ | ||
| 326 | 'type' => 'error', | ||
| 327 | 'value' => $message, | ||
| 328 | ]; | ||
| 329 | } | ||
| 330 | return (new HTTPResponse(json_encode($result), 400)) | ||
| 331 |                 ->addHeader('Content-Type', 'application/json'); | ||
| 332 | } | ||
| 333 | |||
| 334 |         try { | ||
| 335 | $tuple = $upload->load($tmpFile, $folder); | ||
| 336 |         } catch (Exception $e) { | ||
| 337 | $result = [ | ||
| 338 | 'message' => [ | ||
| 339 | 'type' => 'error', | ||
| 340 | 'value' => $e->getMessage(), | ||
| 341 | ] | ||
| 342 | ]; | ||
| 343 | return (new HTTPResponse(json_encode($result), 400)) | ||
| 344 |                 ->addHeader('Content-Type', 'application/json'); | ||
| 345 | } | ||
| 346 | |||
| 347 |         if ($upload->isError()) { | ||
| 348 | $result['message'] = [ | ||
| 349 | 'type' => 'error', | ||
| 350 |                 'value' => implode(' ' . PHP_EOL, $upload->getErrors()), | ||
| 351 | ]; | ||
| 352 | return (new HTTPResponse(json_encode($result), 400)) | ||
| 353 |                 ->addHeader('Content-Type', 'application/json'); | ||
| 354 | } | ||
| 355 | |||
| 356 | $tuple['Name'] = basename($tuple['Filename']); | ||
| 357 | return (new HTTPResponse(json_encode($tuple))) | ||
| 358 |             ->addHeader('Content-Type', 'application/json'); | ||
| 359 | } | ||
| 360 | |||
| 361 | /** | ||
| 362 | * Returns a JSON array for history of a given file ID. Returns a list of all the history. | ||
| 363 | * | ||
| 364 | * @param HTTPRequest $request | ||
| 365 | * @return HTTPResponse | ||
| 366 | */ | ||
| 367 | public function apiHistory(HTTPRequest $request) | ||
| 368 |     { | ||
| 369 | // CSRF check not required as the GET request has no side effects. | ||
| 370 |         $fileId = $request->getVar('fileId'); | ||
| 371 | |||
| 372 |         if (!$fileId || !is_numeric($fileId)) { | ||
| 373 | return new HTTPResponse(null, 400); | ||
| 374 | } | ||
| 375 | |||
| 376 | $class = File::class; | ||
| 377 | $file = DataObject::get($class)->byID($fileId); | ||
| 378 | |||
| 379 |         if (!$file) { | ||
| 380 | return new HTTPResponse(null, 404); | ||
| 381 | } | ||
| 382 | |||
| 383 |         if (!$file->canView()) { | ||
| 384 | return new HTTPResponse(null, 403); | ||
| 385 | } | ||
| 386 | |||
| 387 | $versions = Versioned::get_all_versions($class, $fileId) | ||
| 388 | ->limit($this->config()->max_history_entries) | ||
| 389 |             ->sort('Version', 'DESC'); | ||
| 390 | |||
| 391 | $output = array(); | ||
| 392 | $next = array(); | ||
| 393 | $prev = null; | ||
| 394 | |||
| 395 | // swap the order so we can get the version number to compare against. | ||
| 396 | // i.e version 3 needs to know version 2 is the previous version | ||
| 397 |         $copy = $versions->map('Version', 'Version')->toArray(); | ||
| 398 |         foreach (array_reverse($copy) as $k => $v) { | ||
| 399 |             if ($prev) { | ||
| 400 | $next[$v] = $prev; | ||
| 401 | } | ||
| 402 | |||
| 403 | $prev = $v; | ||
| 404 | } | ||
| 405 | |||
| 406 | $_cachedMembers = array(); | ||
| 407 | |||
| 408 | /** @var File $version */ | ||
| 409 |         foreach ($versions as $version) { | ||
| 410 | $author = null; | ||
| 411 | |||
| 412 |             if ($version->AuthorID) { | ||
| 413 |                 if (!isset($_cachedMembers[$version->AuthorID])) { | ||
| 414 | $_cachedMembers[$version->AuthorID] = DataObject::get(Member::class) | ||
| 415 | ->byID($version->AuthorID); | ||
| 416 | } | ||
| 417 | |||
| 418 | $author = $_cachedMembers[$version->AuthorID]; | ||
| 419 | } | ||
| 420 | |||
| 421 |             if ($version->canView()) { | ||
| 422 |                 if (isset($next[$version->Version])) { | ||
| 423 | $summary = $version->humanizedChanges( | ||
| 424 | $version->Version, | ||
| 425 | $next[$version->Version] | ||
| 426 | ); | ||
| 427 | |||
| 428 | // if no summary returned by humanizedChanges, i.e we cannot work out what changed, just show a | ||
| 429 | // generic message | ||
| 430 |                     if (!$summary) { | ||
| 431 |                         $summary = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.SAVEDFILE', "Saved file"); | ||
| 432 | } | ||
| 433 |                 } else { | ||
| 434 |                     $summary = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.UPLOADEDFILE', "Uploaded file"); | ||
| 435 | } | ||
| 436 | |||
| 437 | $output[] = array( | ||
| 438 | 'versionid' => $version->Version, | ||
| 439 |                     'date_ago' => $version->dbObject('LastEdited')->Ago(), | ||
| 440 |                     'date_formatted' => $version->dbObject('LastEdited')->Nice(), | ||
| 441 |                     'status' => ($version->WasPublished) ? _t('File.PUBLISHED', 'Published') : '', | ||
| 442 | 'author' => ($author) | ||
| 443 | ? $author->Name | ||
| 444 |                         : _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.UNKNOWN', "Unknown"), | ||
| 445 | 'summary' => ($summary) | ||
| 446 | ? $summary | ||
| 447 |                         : _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.NOSUMMARY', "No summary available") | ||
| 448 | ); | ||
| 449 | } | ||
| 450 | } | ||
| 451 | |||
| 452 | return | ||
| 453 |             (new HTTPResponse(json_encode($output)))->addHeader('Content-Type', 'application/json'); | ||
| 454 | } | ||
| 455 | |||
| 456 | /** | ||
| 457 | * Redirects 3.x style detail links to new 4.x style routing. | ||
| 458 | * | ||
| 459 | * @param HTTPRequest $request | ||
| 460 | */ | ||
| 461 | public function legacyRedirectForEditView($request) | ||
| 469 | |||
| 470 | /** | ||
| 471 | * Given a file return the CMS link to edit it | ||
| 472 | * | ||
| 473 | * @param File $file | ||
| 474 | * @return string | ||
| 475 | */ | ||
| 476 | public function getFileEditLink($file) | ||
| 489 | |||
| 490 | /** | ||
| 491 | * Get an asset renamer for the given filename. | ||
| 492 | * | ||
| 493 | * @param string $filename Path name | ||
| 494 | * @return AssetNameGenerator | ||
| 495 | */ | ||
| 496 | protected function getNameGenerator($filename) | ||
| 501 | |||
| 502 | /** | ||
| 503 | * @todo Implement on client | ||
| 504 | * | ||
| 505 | * @param bool $unlinked | ||
| 506 | * @return ArrayList | ||
| 507 | */ | ||
| 508 | public function breadcrumbs($unlinked = false) | ||
| 512 | |||
| 513 | |||
| 514 | /** | ||
| 515 | * Don't include class namespace in auto-generated CSS class | ||
| 516 | */ | ||
| 517 | public function baseCSSClasses() | ||
| 521 | |||
| 522 | public function providePermissions() | ||
| 533 | |||
| 534 | /** | ||
| 535 | * Build a form scaffolder for this model | ||
| 536 | * | ||
| 537 |      * NOTE: Volatile api. May be moved to {@see LeftAndMain} | ||
| 538 | * | ||
| 539 | * @param File $file | ||
| 540 | * @return FormFactory | ||
| 541 | */ | ||
| 542 | public function getFormFactory(File $file) | ||
| 555 | |||
| 556 | /** | ||
| 557 | * The form is used to generate a form schema, | ||
| 558 | * as well as an intermediary object to process data through API endpoints. | ||
| 559 | * Since it's used directly on API endpoints, it does not have any form actions. | ||
| 560 |      * It handles both {@link File} and {@link Folder} records. | ||
| 561 | * | ||
| 562 | * @param int $id | ||
| 563 | * @return Form | ||
| 564 | */ | ||
| 565 | public function getFileEditForm($id) | ||
| 569 | |||
| 570 | /** | ||
| 571 | * Get file edit form | ||
| 572 | * | ||
| 573 | * @return Form | ||
| 574 | */ | ||
| 575 | View Code Duplication | public function fileEditForm() | |
| 582 | |||
| 583 | /** | ||
| 584 | * The form is used to generate a form schema, | ||
| 585 | * as well as an intermediary object to process data through API endpoints. | ||
| 586 | * Since it's used directly on API endpoints, it does not have any form actions. | ||
| 587 |      * It handles both {@link File} and {@link Folder} records. | ||
| 588 | * | ||
| 589 | * @param int $id | ||
| 590 | * @return Form | ||
| 591 | */ | ||
| 592 | public function getFileInsertForm($id) | ||
| 596 | |||
| 597 | /** | ||
| 598 | * Get file insert form | ||
| 599 | * | ||
| 600 | * @return Form | ||
| 601 | */ | ||
| 602 | View Code Duplication | public function fileInsertForm() | |
| 609 | |||
| 610 | /** | ||
| 611 | * Abstract method for generating a form for a file | ||
| 612 | * | ||
| 613 | * @param int $id Record ID | ||
| 614 | * @param string $name Form name | ||
| 615 | * @param array $context Form context | ||
| 616 | * @return Form | ||
| 617 | */ | ||
| 618 | protected function getAbstractFileForm($id, $name, $context = []) | ||
| 647 | |||
| 648 | /** | ||
| 649 | * Get form for selecting a file | ||
| 650 | * | ||
| 651 | * @return Form | ||
| 652 | */ | ||
| 653 | public function fileSelectForm() | ||
| 660 | |||
| 661 | /** | ||
| 662 | * Get form for selecting a file | ||
| 663 | * | ||
| 664 | * @param int $id ID of the record being selected | ||
| 665 | * @return Form | ||
| 666 | */ | ||
| 667 | public function getFileSelectForm($id) | ||
| 671 | |||
| 672 | /** | ||
| 673 | * @param array $context | ||
| 674 | * @return Form | ||
| 675 | * @throws InvalidArgumentException | ||
| 676 | */ | ||
| 677 | public function getFileHistoryForm($context) | ||
| 719 | |||
| 720 | /** | ||
| 721 | * Gets a JSON schema representing the current edit form. | ||
| 722 | * | ||
| 723 | * WARNING: Experimental API. | ||
| 724 | * | ||
| 725 | * @param HTTPRequest $request | ||
| 726 | * @return HTTPResponse | ||
| 727 | */ | ||
| 728 | public function schema($request) | ||
| 751 | |||
| 752 | /** | ||
| 753 | * Get file history form | ||
| 754 | * | ||
| 755 | * @return Form | ||
| 756 | */ | ||
| 757 | public function fileHistoryForm() | ||
| 768 | |||
| 769 | /** | ||
| 770 | * @param array $data | ||
| 771 | * @param Form $form | ||
| 772 | * @return HTTPResponse | ||
| 773 | */ | ||
| 774 | public function save($data, $form) | ||
| 778 | |||
| 779 | /** | ||
| 780 | * @param array $data | ||
| 781 | * @param Form $form | ||
| 782 | * @return HTTPResponse | ||
| 783 | */ | ||
| 784 | public function publish($data, $form) | ||
| 788 | |||
| 789 | /** | ||
| 790 | * Update thisrecord | ||
| 791 | * | ||
| 792 | * @param array $data | ||
| 793 | * @param Form $form | ||
| 794 | * @param bool $doPublish | ||
| 795 | * @return HTTPResponse | ||
| 796 | */ | ||
| 797 | protected function saveOrPublish($data, $form, $doPublish = false) | ||
| 844 | |||
| 845 | public function unpublish($data, $form) | ||
| 869 | |||
| 870 | /** | ||
| 871 | * @param File $file | ||
| 872 | * | ||
| 873 | * @return array | ||
| 874 | */ | ||
| 875 | public function getObjectFromData(File $file) | ||
| 945 | |||
| 946 | /** | ||
| 947 | * Action handler for adding pages to a campaign | ||
| 948 | * | ||
| 949 | * @param array $data | ||
| 950 | * @param Form $form | ||
| 951 | * @return DBHTMLText|HTTPResponse | ||
| 952 | */ | ||
| 953 | public function addtocampaign($data, $form) | ||
| 969 | |||
| 970 | /** | ||
| 971 | * Url handler for add to campaign form | ||
| 972 | * | ||
| 973 | * @param HTTPRequest $request | ||
| 974 | * @return Form | ||
| 975 | */ | ||
| 976 | public function addToCampaignForm($request) | ||
| 982 | |||
| 983 | /** | ||
| 984 | * @param int $id | ||
| 985 | * @return Form | ||
| 986 | */ | ||
| 987 | public function getAddToCampaignForm($id) | ||
| 1021 | |||
| 1022 | /** | ||
| 1023 | * @return Upload | ||
| 1024 | */ | ||
| 1025 | protected function getUpload() | ||
| 1035 | |||
| 1036 | /** | ||
| 1037 | * Get response for successfully updated record | ||
| 1038 | * | ||
| 1039 | * @param File $record | ||
| 1040 | * @param Form $form | ||
| 1041 | * @return HTTPResponse | ||
| 1042 | */ | ||
| 1043 | protected function getRecordUpdatedResponse($record, $form) | ||
| 1050 | |||
| 1051 | /** | ||
| 1052 | * Scaffold a search form. | ||
| 1053 | * Note: This form does not submit to itself, but rather uses the apiReadFolder endpoint | ||
| 1054 | * (to be replaced with graphql) | ||
| 1055 | * | ||
| 1056 | * @return Form | ||
| 1057 | */ | ||
| 1058 | public function fileSearchForm() | ||
| 1063 | |||
| 1064 | /** | ||
| 1065 | * Allow search form to be accessible to schema | ||
| 1066 | * | ||
| 1067 | * @return Form | ||
| 1068 | */ | ||
| 1069 | public function getFileSearchform() | ||
| 1073 | |||
| 1074 | /** | ||
| 1075 | * Form for creating a new OEmbed object in the WYSIWYG, used by the InsertEmbedModal component | ||
| 1076 | * | ||
| 1077 | * @param null $id | ||
| 1078 | * @return mixed | ||
| 1079 | */ | ||
| 1080 | public function getRemoteCreateForm($id = null) | ||
| 1085 | |||
| 1086 | /** | ||
| 1087 | * Allow form to be accessible for schema | ||
| 1088 | * | ||
| 1089 | * @return mixed | ||
| 1090 | */ | ||
| 1091 | public function remoteCreateForm() | ||
| 1095 | |||
| 1096 | /** | ||
| 1097 | * Form for editing a OEmbed object in the WYSIWYG, used by the InsertEmbedModal component | ||
| 1098 | * | ||
| 1099 | * @return mixed | ||
| 1100 | */ | ||
| 1101 | public function getRemoteEditForm() | ||
| 1109 | |||
| 1110 | /** | ||
| 1111 | * Allow form to be accessible for schema | ||
| 1112 | * | ||
| 1113 | * @return mixed | ||
| 1114 | */ | ||
| 1115 | public function remoteEditForm() | ||
| 1119 | |||
| 1120 | /** | ||
| 1121 | * Capture the schema handling process, as there is validation done to the URL provided before form is generated | ||
| 1122 | * | ||
| 1123 | * @param $request | ||
| 1124 | * @return HTTPResponse | ||
| 1125 | */ | ||
| 1126 | public function schemaWithValidate(HTTPRequest $request) | ||
| 1167 | } | ||
| 1168 | 
This check marks private properties in classes that are never used. Those properties can be removed.