content.api.php

  1. 7.x modules/content/content.api.php
  2. 6.x modules/content/content.api.php

File

modules/content/content.api.php
View source
  1. <?php
  2. /**
  3. * This file is meant to demonstrate how to use hooks in the content module, as a fellow module developer.
  4. */
  5. /**
  6. * Sample hook other modules implement to register a content type.
  7. *
  8. * Simply return an array as illustrated below to register your
  9. * module's content types.
  10. *
  11. * IMPORTNAT: The type's machine name must be a valid variable name.
  12. * No spaces or symbols.
  13. *
  14. * Notice that the fields are set up much as you would set up a form using the
  15. * normal form api.
  16. *
  17. * The content module assumes that a database table has already been created, where every
  18. * field name begins with field__
  19. *
  20. * Also, the table itself should be named content__typename.
  21. *
  22. * @see the Alert module, and its install file.
  23. *
  24. *
  25. */
  26. function hook_content_register_content_type() {
  27. // Example is from the Alert module.
  28. $arr['alert'] = array(
  29. 'title' => 'Alert',
  30. 'description' => 'Signal an alert, notification, or issue to be resolved for a student.',
  31. 'settings' => array(
  32. 'title' => array(
  33. 'label' => t('Title / Short Description'),
  34. 'weight' => 15,
  35. ),
  36. ),
  37. );
  38. // If we are in a popup (dialog)...
  39. if (@$_GET['window_mode'] == 'popup') {
  40. // We want to make sure we redirect to our handler URL, which will close the dialog.
  41. $arr['alert']['settings']['#redirect'] = array(
  42. 'path' => 'content-dialog-handle-after-save',
  43. 'query' => '',
  44. );
  45. }
  46. $fields = array();
  47. $fields['student_id'] = array(
  48. 'type' => 'textfield',
  49. 'label' => 'Student',
  50. 'weight' => 10,
  51. );
  52. $fields['alert_status'] = array(
  53. 'type' => 'select',
  54. 'label' => 'Status',
  55. 'options' => array(
  56. 'open' => t('Open'),
  57. 'closed' => t('Closed'),
  58. ),
  59. 'required' => TRUE,
  60. 'hide_please_select' => TRUE,
  61. 'weight' => 40,
  62. );
  63. $fields['department'] = array(
  64. 'type' => 'select',
  65. 'label' => 'Department',
  66. 'hide_please_select' => TRUE,
  67. 'options' => array(
  68. 'default' => t("Default/None"),
  69. 'finaid' => t('Financial Aid'),
  70. 'reg' => t('Registrar'),
  71. 'stu_aff' => t('Student Affairs'),
  72. ),
  73. 'weight' => 60,
  74. );
  75. $fields['alert_msg'] = array(
  76. 'type' => 'textarea_editor',
  77. 'label' => 'Message',
  78. 'filter' => 'basic',
  79. 'weight' => 70,
  80. );
  81. $fields['visibility'] = array(
  82. 'type' => 'radios',
  83. 'label' => 'Visible to:',
  84. 'options' => array('public' => 'Anyone (incl. student)', 'faculty' => 'Faculty/Staff only'),
  85. 'weight' => 80,
  86. );
  87. $arr['alert']['fields'] = $fields;
  88. return $arr;
  89. }
  90. /**
  91. * This hook is called by the function content_load($cid), and allows other modules
  92. * to act on content which is being loaded. As with other hooks, modules
  93. * act on the hook based on their weight in the modules table in the database.
  94. *
  95. * It should be noted that the content module itself makes use of this
  96. * hook, with its function content_content_load()
  97. */
  98. function hook_content_load(&$content) {
  99. $content->title = "Change the Title";
  100. // No need to return since we passes by reference.
  101. }
  102. /**
  103. * Functionally works the same as hook_content_load() above.
  104. * @see hook_content_load()
  105. */
  106. function hook_content_save(&$content) {
  107. }

Functions

Namesort descending Description
hook_content_load This hook is called by the function content_load($cid), and allows other modules to act on content which is being loaded. As with other hooks, modules act on the hook based on their weight in the modules table in the database.
hook_content_register_content_type Sample hook other modules implement to register a content type.
hook_content_save Functionally works the same as hook_content_load() above.