-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,17 +51,17 @@ public function form(string $name, array $config): FormBuilderInterface | |
* | ||
* @return array{string,array} | ||
*/ | ||
public function field(string $formName, array $definition, array $formConfig): array | ||
public function field(string $formName, array $definition, ?array $options = []): array | ||
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 54 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
|
||
{ | ||
$options = $this->getOptions($formName, $definition, $formConfig); | ||
$fieldOptions = $this->getOptions($formName, $definition, $options); | ||
|
||
$constraints = $this->getConstraints($definition, $options); | ||
$constraints = $this->getConstraints($definition, $fieldOptions); | ||
|
||
if (!empty($constraints)) { | ||
$options['constraints'] = $constraints; | ||
$fieldOptions['constraints'] = $constraints; | ||
} | ||
|
||
return [$this->getType($definition['type']), $options]; | ||
return [$this->getType($definition['type']), $fieldOptions]; | ||
} | ||
|
||
protected function getConstraintClass(string $name): string | ||
|
@@ -88,16 +88,17 @@ protected function getType(string $name): string | |
* | ||
* @return array<mixed> | ||
*/ | ||
protected function getOptions(string $formName, array $definition, array $formConfig): array | ||
protected function getOptions(string $formName, array $definition, ?array $options = []): array | ||
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 91 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
|
||
{ | ||
$options = $definition['options']; | ||
$fieldOptions = $definition['options']; | ||
$formConfig = $options['config']; | ||
Check failure on line 94 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
Check failure on line 94 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.1 with Pimcore ^11.0 (prefer-stable) on ubuntu-latest)
Check failure on line 94 in src/Form/Builder.php GitHub Actions / phpstan (PHP 8.2 with Pimcore ^11.0 (prefer-lowest) on ubuntu-latest)
|
||
|
||
if ($formConfig['translate']['field_labels'] && !empty($options['label'])) { | ||
$options['label'] = $this->translator->trans($options['label']); | ||
if ($formConfig['translate']['field_labels'] && !empty($fieldOptions['label'])) { | ||
$fieldOptions['label'] = $this->translator->trans($fieldOptions['label']); | ||
} | ||
|
||
if (in_array($this->getType($definition['type']), [DateType::class, TimeType::class], true)) { | ||
$options['widget'] ??= 'single_text'; | ||
$fieldOptions['widget'] ??= 'single_text'; | ||
} | ||
if ($this->getType($definition['type']) === ChoiceType::class) { | ||
if ( | ||
|
@@ -111,7 +112,7 @@ protected function getOptions(string $formName, array $definition, array $formCo | |
continue; | ||
} | ||
|
||
$options[$key] = array_combine( | ||
$fieldOptions[$key] = array_combine( | ||
array_map( | ||
fn (string $key): string => $this->translator->trans($key), | ||
array_keys($definition['options'][$key]) | ||
|
@@ -127,14 +128,15 @@ protected function getOptions(string $formName, array $definition, array $formCo | |
$choices->setFieldConfig($formConfig); | ||
} | ||
|
||
$options['choices'] = $choices->choices(); | ||
$options['choice_value'] = fn ($a) => $a; | ||
$options['choice_label'] = fn ($choice, $key, $value) => $choices->choiceLabel($choice, $key, $value); | ||
$options['choice_attr'] = fn ($choice, $key, $value) => $choices->choiceAttribute($choice, $key, $value); | ||
$context = $options['context'] ?? null; | ||
$fieldOptions['choices'] = $choices->choices($context); | ||
$fieldOptions['choice_value'] = fn ($a) => $a; | ||
$fieldOptions['choice_label'] = fn ($choice, $key, $value) => $choices->choiceLabel($choice, $key, $value, $context); | ||
$fieldOptions['choice_attr'] = fn ($choice, $key, $value) => $choices->choiceAttribute($choice, $key, $value, $context); | ||
} | ||
} | ||
|
||
return $options; | ||
return $fieldOptions; | ||
} | ||
|
||
/** | ||
|