You are here

public function FieldsHelper::getNewFieldId in Search API 8

Finds a new unique field identifier on the given index.

Parameters

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

string $propertyPath: The property path on which the field identifier should be based. Only the last component of the property path will be considered.

Return value

string A new unique field identifier on the given index.

Overrides FieldsHelperInterface::getNewFieldId

1 call to FieldsHelper::getNewFieldId()
FieldsHelper::createFieldFromProperty in src/Utility/FieldsHelper.php
Creates a new field on an index based on a property.

File

src/Utility/FieldsHelper.php, line 477

Class

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

Namespace

Drupal\search_api\Utility

Code

public function getNewFieldId(IndexInterface $index, $propertyPath) {
  list(, $suggestedId) = Utility::splitPropertyPath($propertyPath);

  // Avoid clashes with reserved IDs by removing the reserved "search_api_"
  // from our suggested ID.
  $suggestedId = str_replace('search_api_', '', $suggestedId);
  $fieldId = $suggestedId;
  $i = 0;
  while ($index
    ->getField($fieldId)) {
    $fieldId = $suggestedId . '_' . ++$i;
  }
  while ($this
    ->isFieldIdReserved($fieldId)) {
    $fieldId = '_' . $fieldId;
  }
  return $fieldId;
}