flag_comment_flag_test.module 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @file flag_comment_flag_test.module
  4. * Test module for comment flags.
  5. */
  6. /**
  7. * Implements hook_comment_load().
  8. *
  9. * This is only called once when viewing a node with comments, and before
  10. * hook_entity_view() is invoked. We use this to check the initial state of the
  11. * cache.
  12. */
  13. function flag_comment_flag_test_comment_load($comments) {
  14. $flag_get_user_flags_cache = drupal_static('flag_get_user_flags');
  15. // Store the value of the flag_get_user_flags() static cache in the variable,
  16. // so the test can retrieve it.
  17. $tracking_variable = variable_get('flag_comment_flag_test_user_flags_cache_tracking', array());
  18. $tracking_variable['hook_comment_load'] = $flag_get_user_flags_cache;
  19. variable_set('flag_comment_flag_test_user_flags_cache_tracking', $tracking_variable);
  20. }
  21. /**
  22. * Implements hook_entity_view().
  23. *
  24. * Use hook_entity_view() rather than hook_comment_view() so we are in the same
  25. * invocation as flag_entity_view().
  26. */
  27. function flag_comment_flag_test_entity_view($entity, $type, $view_mode, $langcode) {
  28. if ($type == 'comment') {
  29. $flag_get_user_flags_cache = drupal_static('flag_get_user_flags');
  30. // Store the value of the flag_get_user_flags() static cache in the variable,
  31. // so the test can retrieve it.
  32. $tracking_variable = variable_get('flag_comment_flag_test_user_flags_cache_tracking', array());
  33. $tracking_variable['hook_entity_view_' . $entity->cid] = $flag_get_user_flags_cache;
  34. variable_set('flag_comment_flag_test_user_flags_cache_tracking', $tracking_variable);
  35. }
  36. }