@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | $this->formFactory = $formFactory; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - public function createFormFromYaml(string $formConfigYaml, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface |
|
| 26 | + public function createFormFromYaml(string $formConfigYaml, array $formOptions = [ ], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface |
|
| 27 | 27 | { |
| 28 | 28 | $array = Yaml::parse($formConfigYaml); |
| 29 | 29 | $json = json_encode($array); |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | return $this->createFormFromJson($json, $formOptions, $data, $baseFormTypeClass, $groupName); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function createFormFromJson(string $formConfigJson, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface |
|
| 34 | + public function createFormFromJson(string $formConfigJson, array $formOptions = [ ], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface |
|
| 35 | 35 | { |
| 36 | 36 | $formConfig = json_decode($formConfigJson, true); |
| 37 | 37 | |
| 38 | 38 | return $this->createForm($formConfig, $formOptions, $data, $baseFormTypeClass, $groupName); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function createForm(array $formConfig, array $formOptions = [], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface |
|
| 41 | + public function createForm(array $formConfig, array $formOptions = [ ], $data = null, string $baseFormTypeClass = null, string $groupName = null): ?FormInterface |
|
| 42 | 42 | { |
| 43 | 43 | if (empty($formConfig)) { |
| 44 | 44 | return null; |
@@ -53,34 +53,34 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | foreach ($formConfig as $inputName => $inputConfig) { |
| 56 | - $inputType = isset($inputConfig['type']) ? $inputConfig['type'] : 'text'; |
|
| 56 | + $inputType = isset($inputConfig[ 'type' ]) ? $inputConfig[ 'type' ] : 'text'; |
|
| 57 | 57 | |
| 58 | 58 | // Se obtiene la configuración predeterminada |
| 59 | 59 | if (class_exists($inputType)) { |
| 60 | 60 | $inputDefaultConfig = [ |
| 61 | 61 | 'class' => $inputType, |
| 62 | - 'default_options' => [], |
|
| 62 | + 'default_options' => [ ], |
|
| 63 | 63 | ]; |
| 64 | 64 | } else { |
| 65 | 65 | $inputDefaultConfig = SupportedTypes::getDefaultTypeConfig($inputType); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // se obtienen las opciones definidas para este input |
| 69 | - $inputOptions = isset($inputConfig['options']) ? $inputConfig['options'] : []; |
|
| 69 | + $inputOptions = isset($inputConfig[ 'options' ]) ? $inputConfig[ 'options' ] : [ ]; |
|
| 70 | 70 | |
| 71 | - $inputOptions['constraints'] = $this->getConstraints($inputType, $inputDefaultConfig['default_options'], $inputOptions); |
|
| 71 | + $inputOptions[ 'constraints' ] = $this->getConstraints($inputType, $inputDefaultConfig[ 'default_options' ], $inputOptions); |
|
| 72 | 72 | |
| 73 | 73 | // Se compilan las opciones default con las definidas |
| 74 | 74 | $inputOptions = array_merge( |
| 75 | - $inputDefaultConfig['default_options'], |
|
| 75 | + $inputDefaultConfig[ 'default_options' ], |
|
| 76 | 76 | $inputOptions |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | 79 | // Se crea el input de formulario |
| 80 | 80 | if ($groupName) { |
| 81 | - $form->get($groupName)->add($inputName, $inputDefaultConfig['class'], $inputOptions); |
|
| 81 | + $form->get($groupName)->add($inputName, $inputDefaultConfig[ 'class' ], $inputOptions); |
|
| 82 | 82 | } else { |
| 83 | - $form->add($inputName, $inputDefaultConfig['class'], $inputOptions); |
|
| 83 | + $form->add($inputName, $inputDefaultConfig[ 'class' ], $inputOptions); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
@@ -89,31 +89,31 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | private function getConstraints(string $inputType, array $inputDefaultOptions, array $inputOptions) |
| 91 | 91 | { |
| 92 | - $ret = []; |
|
| 92 | + $ret = [ ]; |
|
| 93 | 93 | |
| 94 | - $validations = isset($inputDefaultOptions['constraints']) ? $inputDefaultOptions['constraints'] : []; |
|
| 95 | - $validations = array_merge($validations, isset($inputOptions['constraints']) ? $inputOptions['constraints'] : []); |
|
| 94 | + $validations = isset($inputDefaultOptions[ 'constraints' ]) ? $inputDefaultOptions[ 'constraints' ] : [ ]; |
|
| 95 | + $validations = array_merge($validations, isset($inputOptions[ 'constraints' ]) ? $inputOptions[ 'constraints' ] : [ ]); |
|
| 96 | 96 | |
| 97 | 97 | foreach ($validations as $validation => $validationOptions) { |
| 98 | 98 | switch ($validation) { |
| 99 | 99 | case 'not_blank': |
| 100 | - if (isset($inputOptions['required']) && false === $inputOptions['required']) { |
|
| 100 | + if (isset($inputOptions[ 'required' ]) && false === $inputOptions[ 'required' ]) { |
|
| 101 | 101 | // no se setea la validación |
| 102 | 102 | } else { |
| 103 | - $ret[] = new NotBlank($validationOptions); |
|
| 103 | + $ret[ ] = new NotBlank($validationOptions); |
|
| 104 | 104 | } |
| 105 | 105 | break; |
| 106 | 106 | case 'email': |
| 107 | - $ret[] = new Email($validationOptions); |
|
| 107 | + $ret[ ] = new Email($validationOptions); |
|
| 108 | 108 | break; |
| 109 | 109 | case 'url': |
| 110 | - $ret[] = new Url($validationOptions); |
|
| 110 | + $ret[ ] = new Url($validationOptions); |
|
| 111 | 111 | break; |
| 112 | 112 | case 'length': |
| 113 | - $ret[] = new Length($validationOptions); |
|
| 113 | + $ret[ ] = new Length($validationOptions); |
|
| 114 | 114 | break; |
| 115 | 115 | case 'date': |
| 116 | - $ret[] = new Date($validationOptions); |
|
| 116 | + $ret[ ] = new Date($validationOptions); |
|
| 117 | 117 | break; |
| 118 | 118 | } |
| 119 | 119 | } |