class Urls in Search API Field Map 4.x
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls
- 8 src/Plugin/search_api/processor/Urls.php \Drupal\search_api_field_map\Plugin\search_api\processor\Urls
- 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\processorView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Urls:: |
public | function | ||
Urls:: |
public | function | ||
Urls:: |
protected | function | Whether to use the canonical value from Domain Source. |