flag.flag.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /**
  3. * @file
  4. * Contains implementations of flag info hooks.
  5. */
  6. /**
  7. * Implements hook_flag_type_info().
  8. *
  9. * Defines the flag types this module implements.
  10. *
  11. * @return array
  12. * An "array of arrays", keyed by object type. The 'handler' slot
  13. * should point to the PHP class implementing this flag.
  14. */
  15. function flag_flag_type_info() {
  16. // Entity types we specifically cater for.
  17. $definitions = array(
  18. 'node' => array(
  19. 'title' => t('Nodes'),
  20. 'description' => t("Nodes are a Drupal site's primary content."),
  21. 'handler' => 'flag_node',
  22. ),
  23. 'user' => array(
  24. 'title' => t('Users'),
  25. 'description' => t('Users who have created accounts on your site.'),
  26. 'handler' => 'flag_user',
  27. ),
  28. );
  29. if (module_exists('comment')) {
  30. $definitions['comment'] = array(
  31. 'title' => t('Comments'),
  32. 'description' => t('Comments are responses to node content.'),
  33. 'handler' => 'flag_comment',
  34. 'module' => 'comment',
  35. );
  36. }
  37. if (module_exists('taxonomy')) {
  38. $definitions['taxonomy_term'] = array(
  39. 'title' => t('Taxonomy Terms'),
  40. 'description' => t('Taxonomy terms are used to categorize content.'),
  41. 'handler' => 'flag_entity',
  42. 'module' => 'taxonomy',
  43. );
  44. }
  45. return $definitions;
  46. }
  47. /**
  48. * Implements hook_flag_type_info_alter().
  49. *
  50. * Step in and add flag types for any entities not yet catered for, using the
  51. * basic flag_entity handler. This allows other modules to provide more
  52. * specialized handlers for entities in hook_flag_type_info() as normal.
  53. */
  54. function flag_flag_type_info_alter(&$definitions) {
  55. foreach (entity_get_info() as $entity_type => $entity_info) {
  56. // Only add flag support for entities that don't yet have them, and which
  57. // are non-config entities.
  58. if (!isset($definitions[$entity_type]) && empty($entity_info['configuration'])) {
  59. // We deliberately exclude taxonomy vocabularies from the list of
  60. // supported entity types because they aren't fieldable or directly
  61. // viewable, which makes them impossible to flag.
  62. if ($entity_type === 'taxonomy_vocabulary') {
  63. continue;
  64. }
  65. $definitions[$entity_type] = array(
  66. 'title' => $entity_info['label'],
  67. 'description' => t('@entity-type entity', array('@entity-type' => $entity_info['label'])),
  68. 'handler' => 'flag_entity',
  69. );
  70. }
  71. }
  72. }
  73. /**
  74. * Implements hook_flag_link_type_info().
  75. */
  76. function flag_flag_link_type_info() {
  77. return array(
  78. 'toggle' => array(
  79. 'title' => t('JavaScript toggle'),
  80. 'description' => t('An AJAX request will be made and degrades to type "Normal link" if JavaScript is not available.'),
  81. 'uses standard js' => TRUE,
  82. 'uses standard css' => TRUE,
  83. ),
  84. 'normal' => array(
  85. 'title' => t('Normal link'),
  86. 'description' => t('A normal non-JavaScript request will be made and the current page will be reloaded.'),
  87. 'uses standard js' => FALSE,
  88. 'uses standard css' => FALSE,
  89. ),
  90. 'confirm' => array(
  91. 'title' => t('Confirmation form'),
  92. 'description' => t('The user will be taken to a confirmation form on a separate page to confirm the flag.'),
  93. 'options' => array(
  94. 'flag_confirmation' => '',
  95. 'unflag_confirmation' => '',
  96. ),
  97. 'uses standard js' => FALSE,
  98. 'uses standard css' => FALSE,
  99. 'provides form' => TRUE,
  100. ),
  101. );
  102. }