eZ\Publish\Core\Search\Common\FieldNameResolver::getFieldTypes PHP Method

getFieldTypes() public method

The method will check for custom fields if given $criterion implements CustomFieldInterface. With optional parameters $fieldTypeIdentifier and $name specific field type and field from its Indexable implementation can be targeted.
See also: eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface
See also: eZ\Publish\SPI\FieldType\Indexable
public getFieldTypes ( eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion, string $fieldDefinitionIdentifier, null | string $fieldTypeIdentifier = null, null | string $name = null ) : array
$criterion eZ\Publish\API\Repository\Values\Content\Query\Criterion
$fieldDefinitionIdentifier string
$fieldTypeIdentifier null | string
$name null | string
return array
    public function getFieldTypes(Criterion $criterion, $fieldDefinitionIdentifier, $fieldTypeIdentifier = null, $name = null)
    {
        $fieldMap = $this->getSearchableFieldMap();
        $fieldTypeNameMap = [];
        foreach ($fieldMap as $contentTypeIdentifier => $fieldIdentifierMap) {
            // First check if field exists in the current ContentType, there is nothing to do if it doesn't
            if (!isset($fieldIdentifierMap[$fieldDefinitionIdentifier])) {
                continue;
            }
            // If $fieldTypeIdentifier is given it must match current field definition
            if ($fieldTypeIdentifier !== null && $fieldTypeIdentifier !== $fieldIdentifierMap[$fieldDefinitionIdentifier]['field_type_identifier']) {
                continue;
            }
            $fieldNameWithSearchType = $this->getIndexFieldName($criterion, $contentTypeIdentifier, $fieldDefinitionIdentifier, $fieldIdentifierMap[$fieldDefinitionIdentifier]['field_type_identifier'], $name, false);
            $fieldNames = array_keys($fieldNameWithSearchType);
            $fieldName = reset($fieldNames);
            $fieldTypeNameMap[$fieldName] = $fieldNameWithSearchType[$fieldName];
        }
        return $fieldTypeNameMap;
    }

Usage Example

 /**
  * Get array of search fields.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
  *
  * @return \eZ\Publish\SPI\Search\FieldType[] Array of field types indexed by name.
  */
 protected function getSearchFields(Criterion $criterion)
 {
     return $this->fieldNameResolver->getFieldTypes($criterion, $criterion->target);
 }
All Usage Examples Of eZ\Publish\Core\Search\Common\FieldNameResolver::getFieldTypes