You are here

protected function SearchApiCombinedEntityDataSourceController::getPropertyInfo in Search API 7

Retrieves the property info for this item type.

This is a helper method for getMetadataWrapper() that can be used by subclasses to specify the property information to use when creating a metadata wrapper.

The data structure uses largely the format specified in hook_entity_property_info(). However, the first level of keys (containing the entity types) is omitted, and the "properties" key is called "property info" instead. So, an example return value would look like this:

return array(
  'property info' => array(
    'foo' => array(
      'label' => t('Foo'),
      'type' => 'text',
    ),
    'bar' => array(
      'label' => t('Bar'),
      'type' => 'list<integer>',
    ),
  ),
);

SearchApiExternalDataSourceController::getPropertyInfo() contains a working example of this method.

If the item type is an entity type, no additional property information is required, the method will thus just return an empty array. You can still use this to append additional properties to the entities, or the like, though.

Return value

array Property information as specified by entity_metadata_wrapper().

Throws

SearchApiDataSourceException If any error state was encountered.

Overrides SearchApiAbstractDataSourceController::getPropertyInfo

See also

getMetadataWrapper()

hook_entity_property_info()

File

includes/datasource_multiple.inc, line 73
Contains SearchApiCombinedEntityDataSourceController.

Class

SearchApiCombinedEntityDataSourceController
Provides a datasource for indexing multiple types of entities.

Code

protected function getPropertyInfo() {
  $info = array(
    'item_id' => array(
      'label' => t('ID'),
      'description' => t('The combined ID of the item, containing both entity type and entity ID.'),
      'type' => 'token',
    ),
    'item_type' => array(
      'label' => t('Entity type'),
      'description' => t('The entity type of the item.'),
      'type' => 'token',
      'options list' => 'search_api_entity_type_options_list',
    ),
    'item_entity_id' => array(
      'label' => t('Entity ID'),
      'description' => t('The entity ID of the item.'),
      'type' => 'token',
    ),
    'item_bundle' => array(
      'label' => t('Bundle'),
      'description' => t('The bundle of the item, if applicable.'),
      '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) {
    $info[$type] = array(
      'label' => $label,
      'description' => t('The indexed entity, if it is of type %type.', array(
        '%type' => $label,
      )),
      'type' => $type,
    );
  }
  return array(
    'property info' => $info,
  );
}