public function SoulMate::addFieldValues in Search API 8
Adds the values of properties defined by this processor to the item.
Parameters
\Drupal\search_api\Item\ItemInterface $item: The item whose field values should be added.
Overrides ProcessorPluginBase::addFieldValues
File
- tests/
search_api_test_extraction/ src/ Plugin/ search_api/ processor/ SoulMate.php, line 145
Class
- SoulMate
- Adds the user's soul mate node for indexing.
Namespace
Drupal\search_api_test_extraction\Plugin\search_api\processorCode
public function addFieldValues(ItemInterface $item) {
$entity = $item
->getOriginalObject()
->getValue();
if (!$entity instanceof EntityInterface || $entity
->getEntityTypeId() === 'user') {
return;
}
/** @var \Drupal\search_api\Item\FieldInterface[][] $to_extract */
$to_extract = [];
foreach ($item
->getFields() as $field) {
if (!$field
->getDatasourceId()) {
continue;
}
$property_path = $field
->getPropertyPath();
list($direct, $nested) = Utility::splitPropertyPath($property_path, FALSE);
if ($direct === 'soul_mate') {
$to_extract[$nested][] = $field;
}
}
if (!$to_extract) {
return;
}
$user = $this
->getEntityTypeManager()
->getStorage('user')
->load($entity
->id());
if (!$user) {
return;
}
$this
->getFieldsHelper()
->extractFields($user
->getTypedData(), $to_extract, $item
->getLanguage());
}