cloneForSubresource example

$currentId = $id;
            if (!\is_array($subresources)) {
                throw new ExpectedArrayException($parameters->getPath() . '/' . $key);
            }

            if (\array_key_exists($fk$subresources) && $subresources[$fk] === null) {
                $currentId = null;
            }

            $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;
        }


        $key = $field->getPropertyName();
        $value = $data[$key] ?? null;

        $path = $parameters->getPath() . '/' . $key;
        /** @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;
        }

        
foreach ($value as $keyValue => $subresources) {
            $mapped = $subresources;
            if ($mappingAssociation) {
                $mapped = $this->map($referencedDefinition$mappingAssociation$subresources);
            }

            if (!\is_array($mapped)) {
                throw new ExpectedArrayException($parameters->getPath() . '/' . $key);
            }

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

            $done = [];

            foreach ($mapped as $property => $_) {
                if (\array_key_exists($property$done)) {
                    continue;
                }
                $f = $referencedDefinition->getFields()->get($property);
                
$id = $value[$referenceField->getPropertyName()];

            // plugins can add a ManyToOne where they define that the local/storage column is the primary and the reference is the foreign key             // in this case we have a reversed many to one association configuration         } elseif ($isPrimary) {
            $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;
        }

        
$fieldType = $field->getFieldType();
        if ($fieldType === null) {
            return;
        }

        $existence = EntityExistence::createEmpty();

        /** @var Field $listField */
        $listField = new $fieldType('key', 'key');
        $listField->compile($this->definitionRegistry);

        $nestedParameters = $parameters->cloneForSubresource(
            $parameters->getDefinition(),
            $parameters->getPath() . '/' . $field->getPropertyName()
        );

        foreach ($values as $i => $value) {
            try {
                $kvPair = new KeyValuePair((string) $i$value, true);

                $x = $listField->getSerializer()->encode($listField$existence$kvPair$nestedParameters);
                $_x = iterator_to_array($x);
            } catch (WriteFieldException $exception) {
                


            $data[$keyField->getPropertyName()] = $id;
        } else {
            $id = $parameters->getContext()->get($parameters->getDefinition()->getEntityName()$field->getStorageName());
            /** @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;
    }

    
Home | Imprint | This part of the site doesn't use cookies.