@param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions

@return array
348632
public function groupFieldDefinitions(array $fieldDefinitions): array
    {
        $fieldDefinitionsByGroup = [];
        foreach ($this->fieldsGroupsListHelper->getGroups() as $groupId => $groupName) {
            $fieldDefinitionsByGroup[$groupId] = [
                'name' => $groupName,
                'fieldDefinitions' => [],
            ];
        }

        foreach ($fieldDefinitions as $fieldDefinition) {
            $groupId = $fieldDefinition->fieldGroup;
            if (!$groupId) {
                $groupId = $this->fieldsGroupsListHelper->getDefaultGroup();
            }

            $fieldDefinitionsByGroup[$groupId]['fieldDefinitions'][] = $fieldDefinition;
            $fieldDefinitionsByGroup[$groupId]['name'] = $fieldDefinitionsByGroup[$groupId]['name'] ?? $groupId;
        }

        return $fieldDefinitionsByGroup;
    }
268897
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
    {
        $fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings(
            array(
                'isMultiple' => !empty($storageDef->dataInt1) ? (bool)$storageDef->dataInt1 : false,
            )
        );

        $fieldDef->defaultValue->data = empty($storageDef->dataText5)
            ? null
            : explode(',', $storageDef->dataText5);
        // TODO This will contain comma separated country codes, which is correct for value but not for sort key.
        // Sort key should contain comma separated lowercased country names.
        $fieldDef->defaultValue->sortKey = $storageDef->dataText5;
    }
1078173
private function getDefaultSearchFields(array $fieldDescriptors): array
    {
        $defaultSearchFields = [];
        foreach ($fieldDescriptors as $fieldDescriptor) {
            if (FieldDescriptorInterface::SEARCHABILITY_YES === $fieldDescriptor->getSearchability()) {
                $defaultSearchFields[] = $fieldDescriptor->getName();
            }
        }

        return $defaultSearchFields;
    }
283030
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
    {
        $fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings(
            array(
                'textRows' => $storageDef->dataInt1,
            )
        );
        $fieldDef->defaultValue->data = null;
        $fieldDef->defaultValue->sortKey = '';
    }
1185954
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
    {
        $validatorParameters = array('minIntegerValue' => null, 'maxIntegerValue' => null);
        if ($storageDef->dataInt4 & self::HAS_MIN_VALUE) {
            $validatorParameters['minIntegerValue'] = $storageDef->dataInt1;
        }

        if ($storageDef->dataInt4 & self::HAS_MAX_VALUE) {
            $validatorParameters['maxIntegerValue'] = $storageDef->dataInt2;
        }
        $fieldDef->fieldTypeConstraints->validators[self::FLOAT_VALIDATOR_IDENTIFIER] = $validatorParameters;
        $fieldDef->defaultValue->data = $storageDef->dataInt3;
        $fieldDef->defaultValue->sortKey = ($storageDef->dataInt3 === null ? 0 : $storageDef->dataInt3);
    }
683388
public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
    {
        $options = [];
        $multiLingualOptions = [$fieldDef->mainLanguageCode => []];

        if (isset($storageDef->dataText5)) {
            $optionsXml = simplexml_load_string($storageDef->dataText5);
            if ($optionsXml !== false) {
                foreach ($optionsXml->options->option as $option) {
                    $options[(int)$option['id']] = (string)$option['name'];
                }
            }
        }

        if (isset($fieldDef->mainLanguageCode) && !empty($options)) {
            $multiLingualOptions[$fieldDef->mainLanguageCode] = $options;
        }

        foreach ($storageDef->multilingualData as $languageCode => $mlData) {
            $xml = simplexml_load_string($mlData->dataText);
            if ($xml !== false) {
                foreach ($xml->options->option as $option) {
                    $multiLingualOptions[$languageCode][(int)$option['id']] = (string)$option['name'];
                }
            }
        }

        $fieldDef->fieldTypeConstraints->fieldSettings = new FieldSettings([
                'isMultiple' => !empty($storageDef->dataInt1) ? (bool)$storageDef->dataInt1 : false,
                'options' => $options,
                'multilingualOptions' => $multiLingualOptions,
            ]
        );

        // @todo: Can Selection store a default value in the DB?
        $fieldDef->defaultValue = new FieldValue();
        $fieldDef->defaultValue->data = array();
        $fieldDef->defaultValue->sortKey = '';
    }
556301
private function getFieldLayoutFieldsDefinition(array $fields): array
    {
        $fieldDefinitions = [];

        foreach ($fields as $field) {
            $fieldDefinitions[$field->handle] = $field->required;
        }

        return $fieldDefinitions;
    }
575095
public function addFieldDefinitionObject($identifier, $fieldDefinition)
    {
        $this->data['fields'][$identifier] = $this->convertToFieldDefintionObject($identifier, $fieldDefinition);
    }
654196
public function findFieldDefinitions(ContentType $contentType, string $fieldTypeIdentifier): array
    {
        $fieldTypes = [];
        foreach ($contentType->getFieldDefinitions() as $fieldDefinition) {
            if ($fieldDefinition->fieldTypeIdentifier === $fieldTypeIdentifier) {
                $fieldTypes[] = $fieldDefinition;
            }
        }

        return $fieldTypes;
    }
1296236
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
    {
        return array(
            new Search\Field(
                'value',
                // @todo: Data is yet empty, this seems wrong, so we use the
                // sort field for now
                $field->value->sortKey['sort_key_int'] / 1000,
                new Search\FieldType\PriceField()
            ),
            new Search\Field(
                'fulltext',
                $field->value->sortKey['sort_key_int'] / 1000,
                new Search\FieldType\FullTextField()
            ),
        );
    }
494455
private function createObj($reportDefinitionFields)
    {
        $obj = new \stdClass();

        foreach ($reportDefinitionFields as $reportDefinitionField) {
            $name = $reportDefinitionField->getFieldName();
            $obj->$name = [
                'type' => $reportDefinitionField->getFieldType(),
                'values' => ($reportDefinitionField->getEnumValues() !== null) ? $reportDefinitionField->getEnumValues() : null,
            ];

        }

        return $obj;
    }
430773
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
    {
        $storageDef->dataInt1 = isset($fieldDef->fieldTypeConstraints->validators[static::TAGS_VALIDATOR_IDENTIFIER]['subTreeLimit']) ?
            (int) $fieldDef->fieldTypeConstraints->validators[static::TAGS_VALIDATOR_IDENTIFIER]['subTreeLimit'] :
            0;

        $storageDef->dataInt3 = isset($fieldDef->fieldTypeConstraints->fieldSettings['hideRootTag']) ?
            (int) $fieldDef->fieldTypeConstraints->fieldSettings['hideRootTag'] :
            0;

        $storageDef->dataInt4 = isset($fieldDef->fieldTypeConstraints->validators[static::TAGS_VALIDATOR_IDENTIFIER]['maxTags']) ?
            (int) $fieldDef->fieldTypeConstraints->validators[static::TAGS_VALIDATOR_IDENTIFIER]['maxTags'] :
            0;

        $storageDef->dataText1 = isset($fieldDef->fieldTypeConstraints->fieldSettings['editView']) ?
            $fieldDef->fieldTypeConstraints->fieldSettings['editView'] :
            Type::EDIT_VIEW_DEFAULT_VALUE;
    }
402330
public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
    {
        $fieldSettings = $fieldDef->fieldTypeConstraints->fieldSettings;
        $doc = new DOMDocument('1.0', 'utf-8');
        $root = $doc->createElement('related-objects');
        $doc->appendChild($root);

        $constraints = $doc->createElement('constraints');
        if (!empty($fieldSettings['selectionContentTypes'])) {
            foreach ($fieldSettings['selectionContentTypes'] as $typeIdentifier) {
                $allowedClass = $doc->createElement('allowed-class');
                $allowedClass->setAttribute('contentclass-identifier', $typeIdentifier);
                $constraints->appendChild($allowedClass);
                unset($allowedClass);
            }
        }
        $root->appendChild($constraints);

        $selectionType = $doc->createElement('selection_type');
        $selectionMethod = isset($fieldSettings['selectionMethod']) ? (int)$fieldSettings['selectionMethod'] : 0;
        $selectionType->setAttribute('value', $selectionMethod);
        $root->appendChild($selectionType);

        $defaultLocation = $doc->createElement('contentobject-placement');
        if (!empty($fieldSettings['selectionRoot'])) {
            $defaultLocation->setAttribute('node-id', (int)$fieldSettings['selectionRoot']);
        }
        $root->appendChild($defaultLocation);

        $doc->appendChild($root);
        $storageDef->dataText5 = $doc->saveXML();

        // BC: For Backwards Compatibility for legacy and in case of downgrades or data sharing
        // Selection method, 0 = browse, 1 = dropdown
        $storageDef->dataInt1 = $selectionMethod;

        // Selection root, location ID, or 0 if empty
        $storageDef->dataInt2 = (int)$fieldSettings['selectionRoot'];
    }
676171
private function validateBlockTypes(array $blockTypes, array $blockDefinitions): void
    {
        foreach ($blockTypes as $identifier => $blockType) {
            if (!isset($blockDefinitions[$blockType['definition_identifier']])) {
                throw new RuntimeException(
                    sprintf(
                        'Block definition "%s" used in "%s" block type does not exist.',
                        $blockType['definition_identifier'],
                        $identifier
                    )
                );
            }
        }
    }
619341
public function toFieldDefinition(
        StorageFieldDefinition $storageFieldDef,
        FieldDefinition $fieldDef
    ) {
        $converter = $this->converterRegistry->getConverter(
            $fieldDef->fieldType
        );
        $converter->toFieldDefinition(
            $storageFieldDef,
            $fieldDef
        );
    }
530996
protected function loadContentTypeId($fieldDefinitionId)
    {
        $dbHandler = $this->getConnection();

        $query = $dbHandler->createSelectQuery();
        $query->select('contentclass_id')
            ->from($dbHandler->quoteTable('ezcontentclass_attribute'))
            ->where(
                $query->expr->eq('id', $fieldDefinitionId)
            );

        $statement = $query->prepare();
        $statement->execute();

        $row = $statement->fetch(\PDO::FETCH_ASSOC);

        if ($row === false) {
            throw new \RuntimeException(
                sprintf(
                    'Content Type ID cannot be retrieved based on the field definition ID "%s"',
                    $fieldDefinitionId
                )
            );
        }

        return $row['contentclass_id'];
    }
1249067
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
    {
        return array(
            new Search\Field(
                'value_address',
                $field->value->externalData['address'],
                new Search\FieldType\StringField()
            ),
            new Search\Field(
                'value_location',
                array(
                    'latitude' => $field->value->externalData['latitude'],
                    'longitude' => $field->value->externalData['longitude'],
                ),
                new Search\FieldType\GeoLocationField()
            ),
            new Search\Field(
                'fulltext',
                $field->value->externalData['address'],
                new Search\FieldType\FullTextField()
            ),
        );
    }