Skip to content

Commit eb0a065

Browse files
committed
Required options also affect select fields
1 parent b67c375 commit eb0a065

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/Form/Product/ShopCustomerOptionType.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,28 @@ private function getFormConfiguration(
144144
},
145145
'choice_value' => 'code',
146146
];
147-
} else {
148-
$constraint = ConstraintCreator::createFromConfiguration(
149-
$customerOptionType,
150-
$customerOption->getConfiguration()
151-
);
147+
}
152148

153-
if ($constraint !== null) {
154-
$constraint->groups = ['sylius'];
155-
$configuration = ['constraints' => [$constraint]];
156-
}
149+
$constraint = ConstraintCreator::createFromConfiguration(
150+
$customerOptionType,
151+
$customerOption->getConfiguration()
152+
);
157153

158-
if ($customerOption->isRequired()) {
159-
/** @var NotBlank $requiredConstraint */
160-
$requiredConstraint = ConstraintCreator::createRequiredConstraint();
161-
$requiredConstraint->message = 'brille24.form.customer_options.required';
154+
if ($constraint !== null) {
155+
$constraint->groups = ['sylius'];
156+
$configuration = ['constraints' => [$constraint]];
157+
}
162158

163-
$requiredConstraint->groups = ['sylius'];
164-
$configuration['constraints'][] = $requiredConstraint;
165-
}
159+
if ($customerOption->isRequired()) {
160+
/** @var NotBlank $requiredConstraint */
161+
$requiredConstraint = ConstraintCreator::createRequiredConstraint();
162+
$requiredConstraint->message = 'brille24.form.customer_options.required';
163+
164+
$requiredConstraint->groups = ['sylius'];
165+
$configuration['constraints'][] = $requiredConstraint;
166166
}
167167

168+
168169
if ($customerOptionType === CustomerOptionTypeEnum::FILE) {
169170
/*
170171
* Here we give the Customer Option File Type a special block name to override it in a form theme.

src/Services/ConstraintCreator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Brille24\SyliusCustomerOptionsPlugin\Enumerations\CustomerOptionTypeEnum;
88
use Brille24\SyliusCustomerOptionsPlugin\Validator\Constraints\ConditionalConstraint;
99
use Symfony\Component\Validator\Constraint;
10+
use Symfony\Component\Validator\Constraints\Count;
1011
use Symfony\Component\Validator\Constraints\File;
1112
use Symfony\Component\Validator\Constraints\Length;
1213
use Symfony\Component\Validator\Constraints\NotBlank;

0 commit comments

Comments
 (0)