You are here

public function FieldsHelper::createField in Search API 8

Creates a new field object wrapping a field of the given index.

Parameters

\Drupal\search_api\IndexInterface $index: The index to which this field should be attached.

string $fieldIdentifier: The field identifier.

array $fieldInfo: (optional) An array with further configuration for the field.

Return value

\Drupal\search_api\Item\FieldInterface A new field object.

Overrides FieldsHelperInterface::createField

2 calls to FieldsHelper::createField()
FieldsHelper::createFieldFromProperty in src/Utility/FieldsHelper.php
Creates a new field on an index based on a property.
FieldsHelper::extractItemValues in src/Utility/FieldsHelper.php
Extracts property values from items.

File

src/Utility/FieldsHelper.php, line 430

Class

FieldsHelper
Provides helper methods for dealing with Search API fields and properties.

Namespace

Drupal\search_api\Utility

Code

public function createField(IndexInterface $index, $fieldIdentifier, array $fieldInfo = []) {
  $field = new Field($index, $fieldIdentifier);
  foreach ($fieldInfo as $key => $value) {
    $method = 'set' . Container::camelize($key);
    if (method_exists($field, $method)) {
      $field
        ->{$method}($value);
    }
  }
  return $field;
}