upadted to 1.8

This commit is contained in:
Bachir Soussi Chiadmi
2013-09-26 15:49:26 +02:00
parent e0ae80791b
commit 128640cd15
52 changed files with 2604 additions and 1015 deletions
Executable → Regular
+83 -6
View File
@@ -12,6 +12,13 @@
* They are used for loading items, extracting item data, keeping track of the
* item status, etc.
*
* Modules providing implementations of this interface that use a different way
* (either different table or different method altogether) of keeping track of
* indexed/dirty items than SearchApiAbstractDataSourceController should be
* aware that indexes' numerical IDs can change due to feature reverts. It is
* therefore recommended to use search_api_index_update_datasource(), or similar
* code, in a hook_search_api_index_update() implementation.
*
* All methods of the data source may throw exceptions of type
* SearchApiDataSourceException if any exception or error state is encountered.
*/
@@ -237,6 +244,14 @@ interface SearchApiDataSourceControllerInterface {
*/
public function getIndexStatus(SearchApiIndex $index);
/**
* Get the entity type of items from this datasource.
*
* @return string|null
* An entity type string if the items provided by this datasource are
* entities; NULL otherwise.
*/
public function getEntityType();
}
/**
@@ -264,6 +279,15 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
*/
protected $type;
/**
* The entity type for this controller instance.
*
* @var string|null
*
* @see getEntityType()
*/
protected $entityType = NULL;
/**
* The info array for the item type, as specified via
* hook_search_api_item_type_info().
@@ -314,6 +338,21 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
public function __construct($type) {
$this->type = $type;
$this->info = search_api_get_item_type_info($type);
if (!empty($this->info['entity_type'])) {
$this->entityType = $this->info['entity_type'];
}
}
/**
* Get the entity type of items from this datasource.
*
* @return string|null
* An entity type string if the items provided by this datasource are
* entities; NULL otherwise.
*/
public function getEntityType() {
return $this->entityType;
}
/**
@@ -333,19 +372,55 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
*/
public function getMetadataWrapper($item = NULL, array $info = array()) {
$info += $this->getPropertyInfo();
return entity_metadata_wrapper($this->type, $item, $info);
return entity_metadata_wrapper($this->entityType ? $this->entityType : $this->type, $item, $info);
}
/**
* Helper method that can be used by subclasses to specify the property
* information to use when creating a metadata wrapper.
* Get 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 "property" key is called
* "property info" instead. So, an example return value would look like this:
*
* @code
* return array(
* 'property info' => array(
* 'foo' => array(
* 'label' => t('Foo'),
* 'type' => 'text',
* ),
* 'bar' => array(
* 'label' => t('Bar'),
* 'type' => 'list<integer>',
* ),
* ),
* );
* @endcode
*
* 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 array
* Property information as specified by hook_entity_property_info().
* Property information as specified by entity_metadata_wrapper().
*
* @see getMetadataWrapper()
* @see hook_entity_property_info()
*/
protected function getPropertyInfo() {
// If this is an entity type, no additional property info is needed.
if ($this->entityType) {
return array();
}
throw new SearchApiDataSourceException(t('No known property information for type @type.', array('@type' => $this->type)));
}
@@ -689,8 +764,10 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
if ($index->item_type != $this->type) {
$index_type = search_api_get_item_type_info($index->item_type);
$index_type = empty($index_type['name']) ? $index->item_type : $index_type['name'];
$msg = t('Invalid index @index of type @index_type passed to data source controller for type @this_type.',
array('@index' => $index->name, '@index_type' => $index_type, '@this_type' => $this->info['name']));
$msg = t(
'Invalid index @index of type @index_type passed to data source controller for type @this_type.',
array('@index' => $index->name, '@index_type' => $index_type, '@this_type' => $this->info['name'])
);
throw new SearchApiDataSourceException($msg);
}
}