normalizeSingle example

/** * @param array<mixed> $rawData * * @return array<mixed> */
    public function normalize(EntityDefinition $definition, array $rawData, WriteParameterBag $parameters): array
    {
        foreach ($rawData as $i => $row) {
            $parameters->setPath('/' . $i);

            $row = $this->normalizeSingle($definition$row$parameters);

            $rawData[$i] = $row;
        }

        return $rawData;
    }

    /** * @param array<mixed> $data * * @return array<mixed> */
$id = $parameters->getContext()->get($parameters->getDefinition()->getEntityName()$fkField->getPropertyName());
        } else {
            $id = Uuid::randomHex();
            $value[$referenceField->getPropertyName()] = $id;
        }

        $clonedParams = $parameters->cloneForSubresource(
            $field->getReferenceDefinition(),
            $parameters->getPath() . '/' . $key
        );

        $value = $this->writeExtractor->normalizeSingle($field->getReferenceDefinition()$value$clonedParams);

        // in case of a reversed many to one configuration we have to return nothing, otherwise the primary key would be overwritten         if (!$isPrimary) {
            $data[$fkField->getPropertyName()] = $id;
        }

        $data[$key] = $value;

        return $data;
    }

    
$subresources[$fk] = $currentId;

            $clonedParams = $parameters->cloneForSubresource(
                $reference,
                $parameters->getPath() . '/' . $key
            );

            $fkVersionField = $reference->getField($parameters->getDefinition()->getEntityName() . 'VersionId');
            if ($fkVersionField !== null) {
                $subresources = $fkVersionField->getSerializer()->normalize($fkVersionField$subresources$clonedParams);
            }
            $subresources = $this->writeExtractor->normalizeSingle($reference$subresources$clonedParams);

            $value[$keyValue] = $subresources;
        }

        $data[$key] = $value;

        return $data;
    }

    public function encode(
        Field $field,
        
/** @var Field $keyField */
            $keyField = $reference->getFields()->getByStorageName($field->getReferenceField());

            $value[$keyField->getPropertyName()] = $id;
        }

        $clonedParams = $parameters->cloneForSubresource(
            $field->getReferenceDefinition(),
            $parameters->getPath() . '/' . $key
        );

        $value = $this->writeExtractor->normalizeSingle($field->getReferenceDefinition()$value$clonedParams);

        $data[$key] = $value;

        return $data;
    }

    public function encode(
        Field $field,
        EntityExistence $existence,
        KeyValuePair $data,
        WriteParameterBag $parameters
    ):
/** @var EntityTranslationDefinition $referenceDefinition */
        $referenceDefinition = $field->getReferenceDefinition();

        if ($value === null) {
            $languageId = $parameters->getContext()->getContext()->getLanguageId();
            $clonedParams = $parameters->cloneForSubresource(
                $referenceDefinition,
                $path . '/' . $languageId
            );

            $data[$key] = [
                $languageId => $this->writeExtractor->normalizeSingle($referenceDefinition[]$clonedParams),
            ];

            return $data;
        }

        $languageField = $referenceDefinition->getFields()->getByStorageName($field->getLanguageField());
        if ($languageField === null) {
            throw new \RuntimeException(
                sprintf(
                    'Could not find language field "%s" in definition "%s"',
                    $field->getLanguageField(),
                    
Home | Imprint | This part of the site doesn't use cookies.