SearchApiFederatedSolrUrls.php in Search API Federated Solr 7
File
src/SearchApiFederatedSolrUrls.php
View source
<?php
class SearchApiFederatedSolrUrls extends SearchApiAbstractAlterCallback {
protected $index;
protected $options;
public function propertyInfo() {
return [
'urls' => [
'label' => t('URLs'),
'description' => t('URLs pointing to this node on all sites containing'),
'type' => 'list<uri>',
'cardinality' => -1,
],
];
}
public function alterItems(array &$items) {
if ($this
->useDomainAccess()) {
$this
->addDomainUrls($items);
}
else {
$this
->addUrl($items);
}
}
protected function addUrl(array &$items) {
foreach ($items as &$item) {
$url = $this->index
->datasource()
->getItemUrl($item);
if (!$url) {
$item->urls = NULL;
continue;
}
$item->urls = [
url($url['path'], array(
'absolute' => TRUE,
) + $url['options']),
];
}
}
protected function addDomainUrls(array &$items) {
$entity_type = $this->index
->getEntityType();
$entity_info = entity_get_info($entity_type);
foreach ($items as $item) {
$id = entity_id($entity_type, $item);
$entity = current(entity_load($entity_type, [
$id,
]));
if (!$entity) {
return;
}
$urls = domain_get_content_urls($entity);
if (!empty($urls)) {
$item->urls = $urls;
}
else {
$list = [
$item,
];
$this
->addUrl($list);
}
}
}
protected function useDomainAccess() {
return function_exists('domain_get_content_urls');
}
}
Classes
Name |
Description |
SearchApiFederatedSolrUrls |
Class SearchApiFederatedSolrUrls
Provides a Search API index data alteration that adds the sites that the
content is available on to each indexed item. |