workflow_search_api.module 863 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * @file
  4. * Adds workflow state information to Search API index.
  5. */
  6. /**
  7. * Implements hook_entity_property_info_alter().
  8. */
  9. function workflow_search_api_entity_property_info_alter(&$info) {
  10. $info['node']['properties']['workflow_state_name'] = array(
  11. 'type' => 'text',
  12. 'label' => t('Workflow state name'),
  13. 'sanitized' => TRUE,
  14. 'getter callback' => 'workflow_search_api_property_workflow_state_getter_callback',
  15. );
  16. }
  17. /**
  18. * Getter callback for workflow state defined in workflow_search_api_entity_property_info_alter.
  19. */
  20. function workflow_search_api_property_workflow_state_getter_callback($item) {
  21. if ($item->workflow) {
  22. // Get text value of workflow state.
  23. $state = workflow_get_workflow_states_by_sid($item->workflow);
  24. $state_name = $state->state;
  25. }
  26. else {
  27. $state_name = '';
  28. }
  29. return $state_name;
  30. }