callback_node_status.inc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @file
  4. * Contains the SearchApiAlterNodeStatus class.
  5. */
  6. /**
  7. * Exclude unpublished nodes from node indexes.
  8. */
  9. class SearchApiAlterNodeStatus extends SearchApiAbstractAlterCallback {
  10. /**
  11. * Check whether this data-alter callback is applicable for a certain index.
  12. *
  13. * Returns TRUE only for indexes on nodes.
  14. *
  15. * @param SearchApiIndex $index
  16. * The index to check for.
  17. *
  18. * @return boolean
  19. * TRUE if the callback can run on the given index; FALSE otherwise.
  20. */
  21. public function supportsIndex(SearchApiIndex $index) {
  22. return $index->item_type === 'node';
  23. }
  24. /**
  25. * Alter items before indexing.
  26. *
  27. * Items which are removed from the array won't be indexed, but will be marked
  28. * as clean for future indexing.
  29. *
  30. * @param array $items
  31. * An array of items to be altered, keyed by item IDs.
  32. */
  33. public function alterItems(array &$items) {
  34. foreach ($items as $nid => &$item) {
  35. if (empty($item->status)) {
  36. unset($items[$nid]);
  37. }
  38. }
  39. }
  40. }