foldershare-8.x-1.2/foldershare.api.php
foldershare.api.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | <?php /** * @file * Documents the principal hooks available in the module. * * This file provides sample definitions for hooks that are available * to respond to and override access control requests and operations * that create, delete, save, load, insert, update, view, index, and search * file and folder entities. * * Access control hooks are provided by the Drupal core * EntityAccessControlHandler used as a base class for FolderShare * access control. Please see that class for further discussion of * these hooks. * * Entity create, delete, etc., hooks are provided by the Drupal core * EntityStorageBase and ContentEntityStorageBase classes used by * the core Entity and ContentEntity classes, respectively. And ContentEntity * is the base class for FolderShare entity mangement. Please see those * classes for further discussion of these hooks. * * View and form hooks are provided by the Drupal core EntityViewBuilder * and EntityForm base classes used by FolderShare. Please see those classes * for further discussion of these hooks. * * Search index and result hooks are provided by FolderShare's * FolderShareSearch class that defines a Drupal core Search plugin for * searching files and folders. Please see that class for further * discussion of these hooks. * * @addtogroup hooks * * @todo This file only documents hooks for the primary FolderShare entity, * which manages system content. It needs to be updated to include hooks * for other entity types in the module. * @{ */ use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; use Drupal\foldershare\FolderShareInterface; /*---------------------------------------------------------------------- * * Operations that create and affect files and folders. * *----------------------------------------------------------------------*/ /** * Responds after completion of operations that add files. * * This includes operations that upload files, create a new ZIP archive * file from existing files, or unarchive a ZIP file into multiple new files. * * @param \Drupal\foldershare\FolderShareInterface $entity * The parent entity. When NULL, the parent is a root list. * @param \Drupal\foldershare\FolderShareInterface[] $fileEntities * An array of added entities. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_add_files( FolderShareInterface $entity = NULL, array $fileEntities , int $requestingUid ) { } /** * Responds after completion of a "Change owner" operation. * * @param \Drupal\foldershare\FolderShareInterface $entity * The changed entity. * @param int $fromUid * The user ID of the entity before it was changed. * @param int $toUid * The user ID of the entity after it was changed. This will equal * $entity->getOwnerId(). * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_change_owner( FolderShareInterface $entity , int $fromUid , int $toUid , int $requestingUid ) { } /** * Responds after completion of a "Copy" operation. * * Folder tree copies will call this hook after each individual file or * folder is copied. * * @param \Drupal\foldershare\FolderShareInterface $entity * The new entity. * @param \Drupal\foldershare\FolderShareInterface $origEntity * The original entity that was copied. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_copy( FolderShareInterface $entity , FolderShareInterface $origEntity , int $requestingUid ) { } /** * Responds after completion of a "Delete" operation. * * @param int $entityId * The delete entity's ID. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_delete( int $entityId , int $requestingUid ) { } /** * Responds after completion of a "Download" operation. * * @param \Drupal\foldershare\FolderShareInterface $entity * The downloaded entity. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_download( FolderShareInterface $entity , int $requestingUid ) { } /** * Responds after completion of an "Edit" operation. * * @param \Drupal\foldershare\FolderShareInterface $entity * The edited entity. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_edit( FolderShareInterface $entity , int $requestingUid ) { } /** * Responds after completion of a "Move" operation. * * @param \Drupal\foldershare\FolderShareInterface $entity * The moved entity. * @param \Drupal\foldershare\FolderShareInterface $oldParent * The old parent. * @param \Drupal\foldershare\FolderShareInterface $newParent * The new parent. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_move( FolderShareInterface $entity , FolderShareInterface $oldParent = NULL, FolderShareInterface $newParent = NULL, int $requestingUid ) { } /** * Responds after completion of a "New folder" operation. * * If the operation creates a new root folder, $entity->isRootItem() will * be TRUE. Otherwise the operation created a new subfolder. * * @param \Drupal\foldershare\FolderShareInterface $entity * The newly created entity. * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_new_folder( FolderShareInterface $entity , int $requestingUid ) { } /** * Responds after completion of a "Rename" operation. * * @param \Drupal\foldershare\FolderShareInterface $entity * The newly created entity. * @param string $oldName * The previous name for the entity. * @param string $newName * The new name for the entity. This will equal $entity->getName(). * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_rename( FolderShareInterface $entity , string $oldName , string $newName , int $requestingUid ) { } /** * Responds after completion of a "Share" operation. * * The access grants array arguments are both unordered associative arrays * with user IDs as keys and arrays as values. Array values contain strings * indicating 'view' or 'author' access. * * @param \Drupal\foldershare\FolderShareInterface $entity * The newly created entity. * @param array $oldGrants * The previous access grants. * @param array $newGrants * The new access grants. This will equal $entity->getAccessGrants(). * @param int $requestingUid * The user ID of the user requesting the operation. This may differ from * the current user ID, such as when the operation takes place via a * background task. */ function hook_foldershare_post_operation_share( FolderShareInterface $entity , array $oldGrants , array $newGrants , int $requestingUid ) { } /*---------------------------------------------------------------------- * * Access control. * *----------------------------------------------------------------------*/ /** * Controls access to a FolderShare entity. * * FolderShare's access control mechanism has these steps: * - Check if the user is an admin * - Check user permissions. * - Check entity access grants. * - Invoke this hook. * * Steps are executed in order and the remaining steps are skipped if there * is a definitive answer for a step. For instance, if the user is an * administrator, they are granted access and the remaining steps are not * executed. If the user does not have permission or the entity does not * grant them access, then they are denied access and the remaining steps * are not executed. This means this hook is only executed if the user * is not an admin and does have permission and access granted. This hook, * then, can only make a final allow/deny choice. * * @param \Drupal\foldershare\FolderShareInterface $entity * The entity the user wishes to access. If the entity is NULL, the user * is requesting access to the root folder list. * @param string $op * The operation to be performed. Access operators are one of: * - 'create'. * - 'delete'. * - 'share'. * - 'update'. * - 'view'. * @param \Drupal\Core\Session\AccountInterface $account * The user's account. * * @return \Drupal\Core\Access\AccessResultInterface * Returns the access result to allow or forbid access, or have a neutral * opinion. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityAccessControlHandler * @see \Drupal\foldershare\Entity\FolderShareAccessControlHandler */ function hook_foldershare_access( FolderShareInterface $entity , string $op , AccountInterface $account ) { // A hook could query additional database tables to determine if access // should be denied. For instance, special values could mark an entity // as immutable due to some external contract. For instance, a legal // or accounting requirement might require that certain entities be locked // to limit access or changes. return AccessResult::neutral(); } /** * Controls access to create a FolderShare entity. * * @param \Drupal\Core\Session\AccountInterface $account * The user's account. * @param array $context * An associative array with additional context values, including at least: * - 'langcode' - the current language code. * - 'parentId' - the entity ID of the parent folder, or * FolderShareInterface::USER_ROOT_LIST if the entity is a root item and * therefore has no parent folder. * @param string $entityBundle * The entity bundle name. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityAccessControlHandler * @see \Drupal\foldershare\Entity\FolderShareAccessControlHandler */ function hook_foldershare_create_access( AccountInterface $account , array $context , $entityBundle ) { return AccessResult::neutral(); } /*---------------------------------------------------------------------- * * Entity create. * *----------------------------------------------------------------------*/ /** * Responds when creating a new FolderShare entity. * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object that has been created, but not yet saved. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare * @see ::hook_foldershare_post_operation_new_folder() */ function hook_foldershare_create(EntityInterface $entity ) { } /** * Responds after initializing the fields of a FolderShare entity. * * This hook runs after a new entity object has just been instantiated. * It can be used to set initial values (e.g. defaults). * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity object to be initialized. * * @ingroup foldershare * * @see \Drupal\Core\Entity\ContentEntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare * @see ::hook_foldershare_post_operation_new_folder() */ function hook_foldershare_field_values_init(FieldableEntityInterface $entity ) { } /*---------------------------------------------------------------------- * * Entity storage load. * *----------------------------------------------------------------------*/ /** * Responds when loading a FolderShare entity. * * Loading an entity goes through these steps: * - Load entity from storage. * - Call Entity's postLoad(). * - Invoke load hooks. * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param array $entities * An associative array of entities with entity IDs as keys. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_load( array $entities ) { // A hook could add virtual fields to the loaded entity, retreiving // their values from other database tables or computing them. } /*---------------------------------------------------------------------- * * Entity storage save. * *----------------------------------------------------------------------*/ /** * Responds before a FolderShare entity is validated and saved. * * Saving an entity goes through these steps: * - Call ContentEntityBase's preSave(). * - Invoke each field's presave hooks. * - Invoke presave hooks. * - Save the entity to storage. * - Call ContentEntityBase's postSave(). * - Invoke each field's update or insert hooks. * - Invoke update or insert hooks. * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object that has been created, but not yet saved. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_presave(EntityInterface $entity ) { } /*---------------------------------------------------------------------- * * Entity storage insert and update. * *----------------------------------------------------------------------*/ /** * Responds after a new FolderShare entity has been stored. * * Saving a new entity goes through these steps: * - Call ContentEntityBase's preSave(). * - Invoke each field's presave hooks. * - Invoke presave hooks. * - Save the entity to storage. * - Call ContentEntityBase's postSave(). * - Invoke each field's insert hooks. * - Invoke insert hooks. * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object that has been created, but not yet saved. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_insert(EntityInterface $entity ) { // A hook could save any of its own information about the entity into // its own database tables. It may not modify the $entity. } /** * Responds after storage has been updated for a changed FolderShare entity. * * Saving an updated entity goes through these steps: * - Call ContentEntityBase's preSave(). * - Invoke each field's presave hooks. * - Invoke presave hooks. * - Save the entity to storage. * - Call ContentEntityBase's postSave(). * - Invoke each field's update hooks. * - Invoke update hooks. * * FolderShare does not override ContentEntityBase's preSave() and postSave(). * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object that is being updated. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_update(EntityInterface $entity ) { // A hook could save any of its own information about the entity into // its own database tables. It may not modify the $entity. } /*---------------------------------------------------------------------- * * Entity storage delete. * *----------------------------------------------------------------------*/ /** * Responds before a FolderShare entity is deleted from storage. * * Deletion of an entity follows these steps: * - Call ContentEntityBase's preDelete(). * - Invoke predelete hooks. * - Delete the entity from storage. * - Call ContentEntityBase's postDelete(). * - Invoke delete hooks. * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object that is about to be deleted. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_predelete(EntityInterface $entity ) { } /** * Responds after a FolderShare entity has been deleted from storage. * * Deletion of an entity follows these steps: * - Call ContentEntityBase's preDelete(). * - Invoke predelete hooks. * - Delete the entity from storage. * - Call ContentEntityBase's postDelete(). * - Invoke delete hooks. * * This is a low-level hook provided by Drupal core. See also higher-level * hooks provide by the FolderShare module. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object that has been deleted from storage. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityStorageBase * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_delete(EntityInterface $entity ) { // A hook could delete any externally saved information associated // with this entity, such as records in its own database tables. } /*---------------------------------------------------------------------- * * View. * *----------------------------------------------------------------------*/ /** * Responds as a FolderShare entity is being assembled before rendering. * * Rendered view creation follows these steps: * - Load entity. * - Create renderable view of the entity. * - Invoke view hooks. * - Invoke view_alter hooks. * * @param array $build * A renderable array representing the entity content. This may include * render elements for pseudo-fields and embedded views, such as for a * view listing the contents of a folder. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object being rendered. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display * The entity view display holding the options configured for the * entity components, such as their weights on a page and their field * formatters. * @param string $viewMode * The name of the view mode. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityViewBuilder * @see \Drupal\foldershare\Entity\FolderShare */ function hook_foldershare_view( array & $build , EntityInterface $entity , EntityViewDisplayInterface $display , $viewMode ) { // A hook could add renderable information about the entity, such as // special marks for favorite entities, indicators for popular or // heavily used entities, or flags indicating problem content. } /** * Responds after a FolderShare entity has been assembled before rendering. * * Rendered view creation follows these steps: * - Load entity. * - Create renderable view of the entity. * - Invoke view hooks. * - Invoke view_alter hooks. * * @param array $build * A renderable array representing the entity content. This may include * render elements for pseudo-fields and embedded views, such as for a * view listing the contents of a folder. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object being rendered. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display * The entity view display holding the options configured for the * entity components, such as their weights on a page and their field * formatters. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityViewBuilder * @see \Drupal\foldershare\Entity\Builder\FolderShareViewBuilder */ function hook_foldershare_view_alter( array & $build , EntityInterface $entity , EntityViewDisplayInterface $display ) { // A hook may be used to do post-processing on a renderable version // of the entity. This could re-arrange content or suppress content. } /** * Responds before a cache has been checked for a renderable FolderShare entity. * * The hook may modify renderable elements relating to cacheing under the * '#cache' key. * * @param array $build * A renderable array representing the entity content. This may include * render elements for pseudo-fields and embedded views, such as for a * view listing the contents of a folder. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object being rendered. * @param string $viewMode * The name of the view mode. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityViewBuilder * @see \Drupal\foldershare\Entity\Builder\FolderShareViewBuilder */ function hook_foldershare_build_defaults_alter( array & $build , EntityInterface $entity , $viewMode ) { // A hook may add or remove cache control, but it should not modify // the build otherwise. } /*---------------------------------------------------------------------- * * Edit form. * *----------------------------------------------------------------------*/ /** * Responds before a FolderShare edit form is created. * * Form creation follows these steps: * - Load entity. * - Invoke prepare_form hooks. * - Build form. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object being edited. * @param string $operation * The current operation. * @param \Drupal\Core\Form\FormStateInterface $formState * The current state of the form. * * @ingroup foldershare * * @see \Drupal\Core\Entity\EntityForm * @see \Drupal\foldershare\Form\EditFolderShare */ function hook_foldershare_prepare_form( EntityInterface $entity , $operation , FormStateInterface $formState ) { // A hook may modify the entity before it a form is created to edit // the entity. This could add or suppress portions of the $entity. } /*---------------------------------------------------------------------- * * Search. * *----------------------------------------------------------------------*/ /** * Appends to search results for a FolderShare entity. * * FolderShare's search results are created by adding entity names, * field values, and file contents to a search index. This index is * then searched to produce a list of search results to present to * the user. This hook may be used to append to those search results. * * @param \Drupal\foldershare\FolderShareInterface $entity * The entity being include in the search results. * * @return array * Returns an associative array with additional named pieces of information * to be included in the search results. This array, along with FolderShare's * array of values, is passed to the search result theme to present. * * @see \Drupal\foldershare\Plugin\Search\FolderShareSearch */ function hook_foldershare_search_result(FolderShareInterface $entity ) { // A hook could query additional database tables for attributes to // include in the search results, such as to mark an item from a // favorites list. return []; } /** * Appends to the search index for a FolderShare entity. * * FolderShare's search indexing accumulates data extracted from an entity, * including its name and the values of its text fields and file content. * This hook may be used to append additional values to the search index. * * @param \Drupal\foldershare\FolderShareInterface $entity * The entity being include in the search index. * * @return string * Returns a string containing additional information to include in the * search index entry for this entity. * * @see \Drupal\foldershare\Plugin\Search\FolderShareSearch */ function hook_foldershare_update_index(FolderShareInterface $entity ) { // A hook could query additional database tables to get further attributes // of an entity. return '' ; } /** * @} */ |