diff --git contrib/search_api_views/includes/handler_field.inc contrib/search_api_views/includes/handler_field.inc index a8fd27f..b5f4b9a 100644 --- contrib/search_api_views/includes/handler_field.inc +++ contrib/search_api_views/includes/handler_field.inc @@ -5,6 +5,8 @@ * don't need any special treatment and don't have special options. * * Handles lists automatically. + * + * @TODO Building off of views_handler_field_prerender_list might give better list handling. */ class SearchApiViewsHandlerField extends views_handler_field { @@ -84,7 +86,7 @@ class SearchApiViewsHandlerField extends views_handler_field { */ public function query() { // Add the field. - $this->query->addField($this->real_field); + $this->field_alias = $this->query->addField($this->real_field); $this->addAdditionalFields(); } @@ -108,7 +110,7 @@ class SearchApiViewsHandlerField extends views_handler_field { } if (!empty($fields) && is_array($fields)) { foreach ($fields as $identifier => $info) { - $this->query->addField(is_array($info) ? $info['field'] : $info); + $this->aliases[$identifier] = $this->query->addField(is_array($info) ? $info['field'] : $info); } } } @@ -126,8 +128,8 @@ class SearchApiViewsHandlerField extends views_handler_field { * @param array $values * The values retrieved from the database. */ - public function render(array $values) { - $value = $values[$this->real_field]; + public function render($values) { + $value = $this->get_value($values); if (is_array($value)) { return $this->renderArray($value, $values); } @@ -137,7 +139,7 @@ class SearchApiViewsHandlerField extends views_handler_field { /** * Render a list of values. */ - protected function renderArray($value, array $values) { + protected function renderArray($value, $values) { if (isset($this->options['list']['mode'])) { if ($this->options['list']['mode'] == 'first') { $value = count($value) ? array_shift($value) : NULL; @@ -165,13 +167,13 @@ class SearchApiViewsHandlerField extends views_handler_field { * Render a value as a link to the entity, if applicable. */ // @todo Let e.g. author:name be linked to author instead - protected function renderLink($value, array $values) { + protected function renderLink($value, $values) { $render = $this->renderValue($value, $values); if (!$this->options['link_to_entity']) { return $render; } - $entity = $values['entity']; - $type = isset($values['search_api_views_entity_type']) ? $values['search_api_views_entity_type'] : $this->query->getIndex()->entity_type; + $entity = $values->entity; + $type = isset($values->search_api_views_entity_type) ? $values->search_api_views_entity_type : $this->query->getIndex()->entity_type; $url = entity_uri($type, $entity); return l($render, $url['path'], array('html' => TRUE) + $url['options']); } diff --git contrib/search_api_views/includes/handler_field_entity.inc contrib/search_api_views/includes/handler_field_entity.inc index 4a6913a..e0f7c66 100644 --- contrib/search_api_views/includes/handler_field_entity.inc +++ contrib/search_api_views/includes/handler_field_entity.inc @@ -46,7 +46,7 @@ class SearchApiViewsHandlerFieldEntity extends SearchApiViewsHandlerField { /** * Render a value as a link to the entity, if applicable. */ - protected function renderLink($value, array $values) { + protected function renderLink($value, $values) { $render = $this->renderValue($value, $values); if (!$this->options['link_to_entity'] || !is_numeric($value)) { return $render; diff --git contrib/search_api_views/includes/query.inc contrib/search_api_views/includes/query.inc index a064c1f..79c3764 100644 --- contrib/search_api_views/includes/query.inc +++ contrib/search_api_views/includes/query.inc @@ -89,6 +89,7 @@ class SearchApiViewsQuery extends views_plugin_query { */ public function addField($field) { $this->fields[$field] = TRUE; + return $field; } /** @@ -160,8 +161,8 @@ class SearchApiViewsQuery extends views_plugin_query { $wrapper = entity_metadata_wrapper($this->index->entity_type, $result['entity']); $fields = $this->extractFields($wrapper, $this->fields); if ($fields) { - $view->result[$id] = $fields; - $view->result[$id]['search_api_relevance'] = $result['score']; + $view->result[$id] = (object) $fields; + $view->result[$id]->search_api_relevance = $result['score']; } else { $ids[] = $id; @@ -182,9 +183,9 @@ class SearchApiViewsQuery extends views_plugin_query { continue; } $wrapper = entity_metadata_wrapper($this->index->entity_type, $entity); - $view->result[$id]['entity'] = $entity; - $view->result[$id]['search_api_relevance'] = $results[$id]['score']; - $view->result[$id] += $this->extractFields($wrapper, $this->fields); + $view->result[$id] = (object) $this->extractFields($wrapper, $this->fields); + $view->result[$id]->entity = $entity; + $view->result[$id]->search_api_relevance = $results[$id]['score']; } catch (Exception $e) { continue;