/** * {@inheritdoc} */ public function render($row) { $datasource_id = $row->search_api_datasource; if (!$row->_object instanceof ComplexDataInterface) { $context = array('%item_id' => $row->search_api_id, '%view' => $this->view->storage->label()); $this->getLogger()->warning('Failed to load item %item_id in view %view.', $context); return ''; } if (!$this->index->isValidDatasource($datasource_id)) { $context = array('%datasource' => $datasource_id, '%view' => $this->view->storage->label()); $this->getLogger()->warning('Item of unknown datasource %datasource returned in view %view.', $context); return ''; } // Always use the default view mode if it was not set explicitly in the // options. $view_mode = 'default'; $bundle = $this->index->getDatasource($datasource_id)->getItemBundle($row->_object); if (isset($this->options['view_modes'][$datasource_id][$bundle])) { $view_mode = $this->options['view_modes'][$datasource_id][$bundle]; } try { return $this->index->getDatasource($datasource_id)->viewItem($row->_object, $view_mode); } catch (SearchApiException $e) { watchdog_exception('search_api', $e); return ''; } }
/** * {@inheritdoc} */ public function isValidDatasource($datasource_id) { return $this->entity->isValidDatasource($datasource_id); }
/** * React after items were indexed. * * @param \Drupal\search_api\IndexInterface $index * The used index. * @param array $item_ids * An array containing the successfully indexed items' IDs. */ function hook_search_api_items_indexed(\Drupal\search_api\IndexInterface $index, array $item_ids) { if ($index->isValidDatasource('entity:node')) { // Note that this is just an example, and would only work if there are only // nodes indexed in that index (and even then the printed IDs would probably // not be as expected). drupal_set_message(t('Nodes indexed: @ids.', implode(', ', $item_ids))); } }