<?php
/**
 * @file
 * Adds workflow state information to Search API index.
 *
 * This is only valid for Workflow Node, not Workflow Field.
 */

/**
 * Implements hook_entity_property_info_alter().
 */
function workflow_search_api_entity_property_info_alter(&$info) {
  $info['node']['properties']['workflow_state_name'] = array(
    'type' => 'text',
    'label' => t('Workflow state label'),
    'sanitized' => TRUE,
    'getter callback' => 'workflow_search_api_property_workflow_state_getter_callback',
  );
}

/**
 * Getter callback for workflow state defined in workflow_search_api_entity_property_info_alter.
 */
function workflow_search_api_property_workflow_state_getter_callback($node) {
  // Get text value of workflow state. Only for Workflow Node.
  $field_name = ''; // An explicit var is needed.
  $sid = workflow_node_current_state($node, 'node', $field_name);
  return workflow_get_sid_label($sid);
}
