callback_comment_access.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @file
  4. * Contains the SearchApiAlterCommentAccess class.
  5. */
  6. /**
  7. * Adds node access information to comment indexes.
  8. */
  9. class SearchApiAlterCommentAccess extends SearchApiAlterNodeAccess {
  10. /**
  11. * Overrides SearchApiAlterNodeAccess::supportsIndex().
  12. *
  13. * Returns TRUE only for indexes on comments.
  14. */
  15. public function supportsIndex(SearchApiIndex $index) {
  16. return $index->getEntityType() === 'comment';
  17. }
  18. /**
  19. * Overrides SearchApiAlterNodeAccess::getNode().
  20. *
  21. * Returns the comment's node, instead of the item (i.e., the comment) itself.
  22. */
  23. protected function getNode($item) {
  24. return node_load($item->nid);
  25. }
  26. /**
  27. * Overrides SearchApiAlterNodeAccess::configurationFormSubmit().
  28. *
  29. * Doesn't index the comment's "Author".
  30. */
  31. public function configurationFormSubmit(array $form, array &$values, array &$form_state) {
  32. $old_status = !empty($form_state['index']->options['data_alter_callbacks']['search_api_alter_comment_access']['status']);
  33. $new_status = !empty($form_state['values']['callbacks']['search_api_alter_comment_access']['status']);
  34. if (!$old_status && $new_status) {
  35. $form_state['index']->options['fields']['status']['type'] = 'boolean';
  36. }
  37. return parent::configurationFormSubmit($form, $values, $form_state);
  38. }
  39. }