You are here

public function Glossary::getPropertyDefinitions in Search API AZ Glossary 8.4

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/Glossary.php \Drupal\search_api_glossary\Plugin\search_api\processor\Glossary::getPropertyDefinitions()

Retrieves the properties this processor defines for the given datasource.

Property names have to start with a letter or an underscore, followed by any number of letters, numbers and underscores. To avoid collisions, it is also recommended to prefix the property name with the identifier of the module defining the processor.

Parameters

\Drupal\search_api\Datasource\DatasourceInterface|null $datasource: (optional) The datasource this set of properties belongs to. If NULL, the datasource-independent properties should be added (or modified).

Return value

\Drupal\search_api\Processor\ProcessorPropertyInterface[] An array of property definitions for that datasource, keyed by property names.

Overrides ProcessorPluginBase::getPropertyDefinitions

File

src/Plugin/search_api/processor/Glossary.php, line 46

Class

Glossary
Adds the item's AZ to the indexed data.

Namespace

Drupal\search_api_glossary\Plugin\search_api\processor

Code

public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
  $properties = [];
  if (!$datasource) {

    // 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])) {
        $definition = [
          'label' => 'Glossary AZ - ' . Html::escape($fields[$name]
            ->getPrefixedLabel()),
          'description' => 'Glossary AZ - ' . Html::escape($fields[$name]
            ->getPrefixedLabel()),
          // ElasticSearch facets will need this field to be string.
          'type' => 'string',
          'processor_id' => $this
            ->getPluginId(),
          // This will be a hidden field,
          // not something a user can add/remove manually.
          'hidden' => TRUE,
        ];
        $new_field_name = $this
          ->makeFieldName($name);
        $properties[$new_field_name] = new ProcessorProperty($definition);
      }
    }
  }
  return $properties;
}