/**
* Returns index field name for the given parameters.
*
* @param object $criterionOrSortClause
* @param string $contentTypeIdentifier
* @param string $fieldDefinitionIdentifier
* @param string $fieldTypeIdentifier
* @param string $name
* @param bool $isSortField
*
* @return string
*/
public function getIndexFieldName($criterionOrSortClause, $contentTypeIdentifier, $fieldDefinitionIdentifier, $fieldTypeIdentifier, $name, $isSortField)
{
// If criterion or sort clause implements CustomFieldInterface and custom field is set for
// ContentType/FieldDefinition, return it
if ($criterionOrSortClause instanceof CustomFieldInterface && ($customFieldName = $criterionOrSortClause->getCustomField($contentTypeIdentifier, $fieldDefinitionIdentifier))) {
return [$customFieldName => null];
}
// Else, generate field name from field type's index definition
$indexFieldType = $this->fieldRegistry->getType($fieldTypeIdentifier);
// If $name is not given use default field name
if ($name === null) {
if ($isSortField) {
$name = $indexFieldType->getDefaultSortField();
} else {
$name = $indexFieldType->getDefaultMatchField();
}
}
$indexDefinition = $indexFieldType->getIndexDefinition();
// Should only happen by mistake, so let's throw if it does
if (!isset($indexDefinition[$name])) {
throw new RuntimeException("Could not find '{$name}' field in '{$fieldTypeIdentifier}' field type's index definition");
}
$field = $this->nameGenerator->getTypedName($this->nameGenerator->getName($name, $fieldDefinitionIdentifier, $contentTypeIdentifier), $indexDefinition[$name]);
return [$field => $indexDefinition[$name]];
}