diff --git a/includes/datasource_multiple.inc b/includes/datasource_multiple.inc index 13b8881..75adf45 100644 --- a/includes/datasource_multiple.inc +++ b/includes/datasource_multiple.inc @@ -91,6 +91,14 @@ class SearchApiCombinedEntityDataSourceController extends SearchApiAbstractDataS 'type' => 'token', 'options list' => 'search_api_combined_bundle_options_list', ), + 'item_label' => array( + 'label' => t('Label'), + 'description' => t('The label of the item.'), + 'type' => 'text', + // Since this needs a bit more computation than the others, we don't + // include it always when loading the item but use a getter callback. + 'getter callback' => 'search_api_get_multi_type_item_label', + ), ); foreach ($this->getSelectedEntityTypeOptions() as $type => $label) { @@ -115,8 +123,7 @@ class SearchApiCombinedEntityDataSourceController extends SearchApiAbstractDataS * {@inheritdoc} */ public function getItemLabel($item) { - $label = entity_label($item->item_type, $item->{$item->item_type}); - return $label ? $label : NULL; + return search_api_get_multi_type_item_label($item); } /** diff --git a/search_api.module b/search_api.module index 08919e9..dcec490 100644 --- a/search_api.module +++ b/search_api.module @@ -2884,6 +2884,24 @@ function search_api_combined_bundle_options_list() { } /** + * Retrieves a human-readable label for a multi-type index item. + * + * Provided as a non-object alternative to + * SearchApiCombinedEntityDataSourceController::getItemLabel() so it can be used + * as a getter callback. + * + * @param object $item + * An item of the "multiple" item type. + * + * @return string|null + * Either a human-readable label for the item, or NULL if none is available. + */ +function search_api_get_multi_type_item_label($item) { + $label = entity_label($item->item_type, $item->{$item->item_type}); + return $label ? $label : NULL; +} + +/** * Shutdown function which indexes all queued items, if any. */ function _search_api_index_queued_items() {