file_entity_test.module 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * File Entity Test
  5. */
  6. /**
  7. * Implements hook_menu().
  8. */
  9. function file_entity_test_menu() {
  10. $items = array();
  11. $items['file-entity-test/file/add'] = array(
  12. 'title' => 'Add file',
  13. 'page callback' => 'drupal_get_form',
  14. 'page arguments' => array('file_entity_test_add_form'),
  15. 'access arguments' => array('administer site configuration'),
  16. 'file' => 'file_entity_test.pages.inc',
  17. );
  18. $items['file-entity-test/file/%file'] = array(
  19. 'title' => 'View file',
  20. 'page callback' => 'file_entity_test_view_page',
  21. 'page arguments' => array(2),
  22. 'access arguments' => array('administer site configuration'),
  23. 'file' => 'file_entity_test.pages.inc',
  24. );
  25. $items['file-entity-test/file/%file/view'] = array(
  26. 'title' => 'View',
  27. 'type' => MENU_DEFAULT_LOCAL_TASK,
  28. 'weight' => -10,
  29. );
  30. $items['file-entity-test/file/%file/preview'] = array(
  31. 'title' => 'Preview',
  32. 'page callback' => 'file_entity_test_preview_page',
  33. 'page arguments' => array(2),
  34. 'access arguments' => array('administer site configuration'),
  35. 'weight' => 0,
  36. 'type' => MENU_LOCAL_TASK,
  37. 'file' => 'file_entity_test.pages.inc',
  38. );
  39. $items['file-entity-test/file/%file/edit'] = array(
  40. 'title' => 'Edit',
  41. 'page callback' => 'drupal_get_form',
  42. 'page arguments' => array('file_entity_test_edit_form', 2),
  43. 'access arguments' => array('administer site configuration'),
  44. 'weight' => 1,
  45. 'type' => MENU_LOCAL_TASK,
  46. 'file' => 'file_entity_test.pages.inc',
  47. );
  48. return $items;
  49. }
  50. /**
  51. * Implements hook_file_type_info().
  52. */
  53. function file_entity_test_file_type_info() {
  54. return array(
  55. 'file_entity_test' => array(
  56. 'label' => t('Test'),
  57. 'description' => t('A file type defined by the File Entity Test module. Used for testing only.'),
  58. 'claim callback' => 'file_entity_test_file_type_file_entity_test_claim',
  59. 'default view callback' => 'file_entity_test_file_type_file_entity_test_default_view',
  60. 'weight' => 100,
  61. ),
  62. );
  63. }
  64. /**
  65. * Implements hook_file_type_TYPE_claim().
  66. *
  67. * Returns TRUE if the passed in file should be assigned the 'file_entity_test'
  68. * file type.
  69. */
  70. function file_entity_test_file_type_file_entity_test_claim($file) {
  71. return TRUE;
  72. }
  73. /**
  74. * Implements hook_file_type_TYPE_default_view().
  75. */
  76. function file_entity_test_file_type_file_entity_test_default_view($file, $view_mode, $langcode) {
  77. return array(
  78. '#type' => 'link',
  79. '#title' => $file->filename,
  80. '#href' => file_create_url($file->uri),
  81. );
  82. }
  83. /**
  84. * Implements hook_entity_info_alter().
  85. */
  86. function file_entity_test_entity_info_alter(&$entity_info) {
  87. $entity_info['file']['view modes']['file_entity_test_preview'] = array(
  88. 'label' => t('Test Preview'),
  89. 'custom settings' => TRUE,
  90. );
  91. }