You are here

class SearchApiFederatedSolrUrls in Search API Federated Solr 7

Same name and namespace in other branches
  1. 7.3 src/SearchApiFederatedSolrUrls.php \SearchApiFederatedSolrUrls
  2. 7.2 src/SearchApiFederatedSolrUrls.php \SearchApiFederatedSolrUrls

Class SearchApiFederatedSolrUrls Provides a Search API index data alteration that adds the sites that the content is available on to each indexed item.

Hierarchy

Expanded class hierarchy of SearchApiFederatedSolrUrls

1 string reference to 'SearchApiFederatedSolrUrls'
search_api_federated_solr_search_api_alter_callback_info in ./search_api_federated_solr.module
Implements hook_search_api_alter_callback_info().

File

src/SearchApiFederatedSolrUrls.php, line 8

View source
class SearchApiFederatedSolrUrls extends SearchApiAbstractAlterCallback {

  /**
   * @var SearchApiIndex
   */
  protected $index;

  /**
   * @var array
   */
  protected $options;

  /**
   * {@inheritdoc}
   */
  public function propertyInfo() {
    return [
      'urls' => [
        'label' => t('URLs'),
        'description' => t('URLs pointing to this node on all sites containing'),
        'type' => 'list<uri>',
        'cardinality' => -1,
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  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);

      // Get the entity object for the item being indexed, exit if there's somehow not one.
      $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);
      }
    }
  }

  /**
   * Whether to use the site name from Domain Access.
   *
   * @return bool
   */
  protected function useDomainAccess() {
    return function_exists('domain_get_content_urls');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SearchApiAbstractAlterCallback::configurationForm public function Implements SearchApiAlterCallbackInterface::configurationForm(). Overrides SearchApiAlterCallbackInterface::configurationForm 6
SearchApiAbstractAlterCallback::configurationFormSubmit public function Implements SearchApiAlterCallbackInterface::configurationFormSubmit(). Overrides SearchApiAlterCallbackInterface::configurationFormSubmit 4
SearchApiAbstractAlterCallback::configurationFormValidate public function Implements SearchApiAlterCallbackInterface::configurationFormValidate(). Overrides SearchApiAlterCallbackInterface::configurationFormValidate 1
SearchApiAbstractAlterCallback::isMultiEntityIndex protected function Determines whether the given index contains multiple types of entities.
SearchApiAbstractAlterCallback::supportsIndex public function Implements SearchApiAlterCallbackInterface::supportsIndex(). Overrides SearchApiAlterCallbackInterface::supportsIndex 10
SearchApiAbstractAlterCallback::__construct public function Implements SearchApiAlterCallbackInterface::__construct(). Overrides SearchApiAlterCallbackInterface::__construct 1
SearchApiFederatedSolrUrls::$index protected property Overrides SearchApiAbstractAlterCallback::$index
SearchApiFederatedSolrUrls::$options protected property Overrides SearchApiAbstractAlterCallback::$options
SearchApiFederatedSolrUrls::addDomainUrls protected function
SearchApiFederatedSolrUrls::addUrl protected function
SearchApiFederatedSolrUrls::alterItems public function Alter items before indexing. Overrides SearchApiAlterCallbackInterface::alterItems
SearchApiFederatedSolrUrls::propertyInfo public function Implements SearchApiAlterCallbackInterface::propertyInfo(). Overrides SearchApiAbstractAlterCallback::propertyInfo
SearchApiFederatedSolrUrls::useDomainAccess protected function Whether to use the site name from Domain Access.