DummyFields.php in Search API Solr 4.x
File
src/Plugin/search_api/processor/DummyFields.php
View source
<?php
namespace Drupal\search_api_solr\Plugin\search_api\processor;
use Drupal\search_api\Datasource\DatasourceInterface;
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api_solr\Plugin\search_api\processor\Property\DummyFieldProperty;
class DummyFields extends ProcessorPluginBase {
public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
$properties = [];
if ($datasource) {
$definition = [
'label' => $this
->t('Dummy field'),
'description' => $this
->t('Adds dummy field that gets its values via API, for example hook_search_api_solr_documents_alter().'),
'type' => 'string',
'processor_id' => $this
->getPluginId(),
'is_list' => TRUE,
];
$properties['dummy_field'] = new DummyFieldProperty($definition);
}
return $properties;
}
public function addFieldValues(ItemInterface $item) {
$fields = $this
->getFieldsHelper()
->filterForPropertyPath($item
->getFields(), $item
->getDatasourceId(), 'dummy_field');
foreach ($fields as $field) {
$configuration = $field
->getConfiguration();
$field
->addValue($configuration['dummy_value']);
}
}
}