You are here

protected function BackendTestBase::addField in Search API 8

Adds a field to a search index.

The index will not be saved automatically.

Parameters

\Drupal\search_api\IndexInterface $index: The search index.

string $property_name: The property's name.

string $type: (optional) The field type.

1 call to BackendTestBase::addField()
BackendTestBase::regressionTest1916474 in tests/src/Kernel/BackendTestBase.php
Regression tests for correctly indexing multiple float/decimal fields.

File

tests/src/Kernel/BackendTestBase.php, line 1152

Class

BackendTestBase
Provides a base class for backend tests.

Namespace

Drupal\Tests\search_api\Kernel

Code

protected function addField(IndexInterface $index, $property_name, $type = 'text') {
  $field_info = [
    'label' => $property_name,
    'type' => $type,
    'datasource_id' => 'entity:entity_test_mulrev_changed',
    'property_path' => $property_name,
  ];
  $field = \Drupal::getContainer()
    ->get('search_api.fields_helper')
    ->createField($index, $property_name, $field_info);
  $index
    ->addField($field);
  $index
    ->save();
}