You are here

class Urls in Search API Field Map 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls
  2. 8 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls
  3. 8.2 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls

Adds the Urls to the indexed data.

Plugin annotation


@SearchApiProcessor(
  id = "search_api_urls",
  label = @Translation("Urls"),
  description = @Translation("Adds the Urls to the indexed data."),
  stages = {
    "add_properties" = 0,
  },
  locked = true,
  hidden = true,
)

Hierarchy

  • class \Drupal\search_api_field_map\Plugin\search_api\processor\Urls extends \Drupal\search_api\Processor\ProcessorPluginBase

Expanded class hierarchy of Urls

1 string reference to 'Urls'
Urls::getPropertyDefinitions in src/Plugin/search_api/processor/Urls.php

File

src/Plugin/search_api/processor/Urls.php, line 27

Namespace

Drupal\search_api_field_map\Plugin\search_api\processor
View source
class Urls extends ProcessorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
    $properties = [];
    if (!$datasource) {
      $definition = [
        'label' => $this
          ->t('Urls'),
        'description' => $this
          ->t('URLs pointing to this node on all sites containing.'),
        'type' => 'string',
        'processor_id' => $this
          ->getPluginId(),
        'is_list' => TRUE,
      ];
      $properties['search_api_urls'] = new UrlsProperty($definition);
    }
    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public function addFieldValues(ItemInterface $item) {
    $fields = $this
      ->getFieldsHelper()
      ->filterForPropertyPath($item
      ->getFields(), NULL, 'search_api_urls');
    $use_domain = FALSE;
    if ($this
      ->useDomainAccess()) {
      $entity = $item
        ->getOriginalObject()
        ->getValue();
      if ($entity instanceof EntityInterface) {
        $manager = \Drupal::service('domain_access.manager');
        $urls = $manager
          ->getContentUrls($entity);
      }
    }
    else {
      $url = $item
        ->getDatasource()
        ->getItemUrl($item
        ->getOriginalObject());
      if ($url) {
        $urls = [
          $url
            ->setAbsolute()
            ->toString(),
        ];
      }
    }
    if (!empty($urls)) {
      foreach ($fields as $field) {
        foreach ($urls as $url) {
          $field
            ->addValue($url);
        }
      }
    }
  }

  /**
   * Whether to use the canonical value from Domain Source.
   *
   * @return bool
   */
  protected function useDomainAccess() {
    return defined('DOMAIN_ACCESS_FIELD');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Urls::addFieldValues public function
Urls::getPropertyDefinitions public function
Urls::useDomainAccess protected function Whether to use the canonical value from Domain Source.