toEntityArray example

$payload = $this->generateCustomFieldSets($customFields->getCustomFieldSets()$appId);

        $this->customFieldSetRepository->upsert($payload$context);
    }

    private function generateCustomFieldSets(array $customFieldSets, string $appId): array
    {
        $payload = [];

        /** @var CustomFieldSet $customFieldSet */
        foreach ($customFieldSets as $customFieldSet) {
            $payload[] = $customFieldSet->toEntityArray($appId);
        }

        return $payload;
    }
}

    public function testToEntityArray(int $i, array $expectedEntityArray): void
    {
        $cmsExtensions = CmsExtensions::createFromXmlFile(__DIR__ . '/../_fixtures/valid/cmsExtensionsWithBlocks.xml');

        static::assertNotNull($cmsExtensions->getBlocks());
        static::assertEquals(
            $expectedEntityArray,
            $cmsExtensions->getBlocks()->getBlocks()[$i]->toEntityArray('app-id', 'en-GB')
        );
    }

    /** * @return array<array<int|array<string, mixed>>> */
    public static function provideEntityArrays(): array
    {
        return [
            [
                0,
                [
public function updateCmsBlocks(
        CmsExtensions $cmsExtensions,
        string $appId,
        string $defaultLocale,
        Context $context
    ): void {
        $existingCmsBlocks = $this->getExistingCmsBlocks($appId$context);

        $cmsBlocks = $cmsExtensions->getBlocks() !== null ? $cmsExtensions->getBlocks()->getBlocks() : [];
        $upserts = [];
        foreach ($cmsBlocks as $cmsBlock) {
            $payload = $cmsBlock->toEntityArray($appId$defaultLocale);

            $template = $this->blockTemplateLoader->getTemplateForBlock($cmsExtensions$cmsBlock->getName());

            $payload['template'] = $template;
            $payload['styles'] = $this->blockTemplateLoader->getStylesForBlock($cmsExtensions$cmsBlock->getName());

            /** @var AppCmsBlockEntity|null $existing */
            $existing = $existingCmsBlocks->filterByProperty('name', $cmsBlock->getName())->first();
            if ($existing) {
                $payload['id'] = $existing->getId();
                $existingCmsBlocks->remove($existing->getId());
            }
$entityArray['config']['validation'] = 'required';
        }

        if ($this->allowCustomerWrite) {
            $entityArray['allowCustomerWrite'] = true;
        }

        if ($this->allowCartExpose) {
            $entityArray['allowCartExpose'] = true;
        }

        return array_merge_recursive($entityArray$this->toEntityArray());
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function getRequired(): bool
    {
        return $this->required;
    }

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