Ejemplo n.º 1
0
 /**
  * Helper function for adding results to a view in the format expected by the
  * view.
  *
  * Overrides SearchApiViewsQuery::addResults(), as it does not handle
  * multilingual search item IDs (like 'fr_13') properly.
  *
  * @see SearchApiViewsQuery::addResults()
  */
 protected function addResults(array $results, $view)
 {
     // Start with standard way of adding results to the view.
     parent::addResults($results, $view);
     // For multilingual indexes, update entity IDs in $view->result array
     // and remove language code from them, so that they contain real entity IDs
     // stored as integers.
     $controller = search_api_get_datasource_controller($this->index->item_type);
     if ($controller instanceof SearchApiEtDatasourceController) {
         foreach ($view->result as $delta => $result) {
             if (SearchApiEtHelper::isValidItemId($result->entity)) {
                 $entity_id = SearchApiEtHelper::splitItemId($result->entity, SearchApiEtHelper::ITEM_ID_ENTITY_ID);
                 $view->result[$delta]->entity = (int) $entity_id;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider dataProviderSplitItemId
  * @param $expected
  * @param $value
  * @param $parts
  */
 public function testSplitItemId($expected, $value, $parts = NULL)
 {
     $this->assertEquals($expected, SearchApiEtHelper::splitItemId($value, $parts));
 }
 /**
  * {@inheritdoc}
  */
 public function getMetadataWrapper($item = NULL, array $info = array())
 {
     // Since this is usually called with a "property info alter" callback
     // already in place (and only one value is allowed), we have to call
     // the existing callback from within our own callback to make it work.
     $property_info_alter = isset($info['property info alter']) ? $info['property info alter'] : NULL;
     $callback = new SearchApiEtPropertyInfoAlter($property_info_alter);
     $info['property info alter'] = array($callback, 'propertyInfoAlter');
     // If the item isn't the object and a multilingual id is provided
     // extract the entity id to load and wrap the entity.
     if (SearchApiEtHelper::isValidItemId($item)) {
         $item = SearchApiEtHelper::splitItemId($item, SearchApiEtHelper::ITEM_ID_ENTITY_ID);
     }
     $wrapper = entity_metadata_wrapper($this->entityType, $item, $info);
     // If the item's language is set, let's set it on all wrapper fields,
     // so that their translated values get indexed.
     if (!empty($item->search_api_language)) {
         // Set language on the wrapper as a whole.
         $wrapper->language($item->search_api_language);
         // Also try to set language on all wrapper fields, recursively.
         if (!empty($item->search_api_index)) {
             $this->setLanguage($wrapper, $item->search_api_index->options['fields'], $item->search_api_language);
         }
     }
     return $wrapper;
 }