public function Glossary::preIndexSave in Search API AZ Glossary 8.4
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/processor/Glossary.php \Drupal\search_api_glossary\Plugin\search_api\processor\Glossary::preIndexSave()
Preprocesses the search index entity before it is saved.
This can, for example, be used to make sure fields needed by this processor are enabled on the index.
Overrides ProcessorPluginBase::preIndexSave
File
- src/
Plugin/ search_api/ processor/ Glossary.php, line 211
Class
- Glossary
- Adds the item's AZ to the indexed data.
Namespace
Drupal\search_api_glossary\Plugin\search_api\processorCode
public function preIndexSave() {
// Get glossary fields.
$glossary_fields = $this
->getConfig();
// Get original fields from index.
$fields = $this->index
->getFields();
// Loop through the saved config from
// Search API field settings form.
foreach ($glossary_fields as $name => $glossary_field) {
// If glossary is enabled on this field.
if (isset($glossary_field['glossary']) && $glossary_field['glossary'] == 1 && isset($fields[$name])) {
// Automatically add field to index if processor is enabled.
$new_field_name = $this
->makeFieldName($name);
// ElasticSearch facets will need this field to be string.
$field = $this
->ensureField(NULL, $new_field_name, 'string');
// Hide the field.
$field
->setHidden();
}
}
}