addSub example


        return (new DataValidationDefinition())
            ->add('id', new Type('string')new Required())
            ->add('type', new Type('string')new Required())
            ->add('quantity', new Type('int'))
            ->add('payload', new Type('array'))
            ->add('stackable', new Type('bool'))
            ->add('removable', new Type('bool'))
            ->add('label', new Type('string'))
            ->add('referencedId', new Type('string'))
            ->add('coverId', new Type('string')new EntityExists(['entity' => MediaDefinition::ENTITY_NAME, 'context' => Context::createDefaultContext()]))
            ->addSub(
                'priceDefinition',
                (new DataValidationDefinition())
                    ->add('type', new Type('string'))
                    ->add('price', new Type('numeric'))
                    ->add('percentage', new Type('numeric'))
                    ->add('quantity', new Type('int'))
                    ->add('isCalculated', new Type('bool'))
                    ->add('listPrice', new Type('numeric'))
                    ->addList(
                        'taxRules',
                        (new DataValidationDefinition())
                            
$constraints = $this->prepareValidationConstraints($formConfig$allKeys);

                foreach ($constraints as $elementName => $elementConstraints) {
                    $subDefinition->add($elementName, ...$elementConstraints);
                }
            }

            if (empty($subDefinition->getProperties())) {
                continue;
            }

            $definition->addSub($saleChannelId$subDefinition);
        }

        $this->validator->validate($inputData$definition);
    }

    /** * @param array<string, mixed> $formConfig * @param array<string> $inputConfigKeys * * @return array<string, Constraint[]> */
    
foreach ($additionalValidations->getProperties() as $key => $validation) {
                $definition->add($key, ...$validation);
            }
        }

        if ($validateStorefrontUrl) {
            $definition
                ->add('storefrontUrl', new NotBlank()new Choice(array_values($this->getDomainUrls($context))));
        }

        $accountType = $data->get('accountType', CustomerEntity::ACCOUNT_TYPE_PRIVATE);
        $definition->addSub('billingAddress', $this->getCreateAddressValidationDefinition($data$accountType$data->get('billingAddress')$context));

        if ($data->has('shippingAddress')) {
            /** @var DataBag $shippingAddress */
            $shippingAddress = $data->get('shippingAddress');
            $shippingAccountType = $shippingAddress->get('accountType', CustomerEntity::ACCOUNT_TYPE_PRIVATE);
            $definition->addSub('shippingAddress', $this->getCreateAddressValidationDefinition($data$shippingAccountType$shippingAddress$context));
        }

        $billingAddress = $addressData->all();

        if ($data->get('vatIds') instanceof DataBag) {
            
Home | Imprint | This part of the site doesn't use cookies.