@@ 20-212 (lines=193) @@ | ||
17 | * @ORM\Entity |
|
18 | * @ORM\Table(name="kuma_multi_line_text_page_parts") |
|
19 | */ |
|
20 | class MultiLineTextPagePart extends AbstractFormPagePart |
|
21 | { |
|
22 | /** |
|
23 | * If set to true, you are obligated to fill in this page part |
|
24 | * |
|
25 | * @ORM\Column(type="boolean", nullable=true) |
|
26 | */ |
|
27 | protected $required = false; |
|
28 | ||
29 | /** |
|
30 | * Error message shows when the page part is required and nothing is filled in |
|
31 | * |
|
32 | * @ORM\Column(type="string", name="error_message_required", nullable=true) |
|
33 | */ |
|
34 | protected $errorMessageRequired; |
|
35 | ||
36 | /** |
|
37 | * If set the entered value will be matched with this regular expression |
|
38 | * |
|
39 | * @ORM\Column(type="string", nullable=true) |
|
40 | */ |
|
41 | protected $regex; |
|
42 | ||
43 | /** |
|
44 | * If a regular expression is set and it doesn't match with the given value, this error message will be shown |
|
45 | * |
|
46 | * @ORM\Column(type="string", name="error_message_regex", nullable=true) |
|
47 | */ |
|
48 | protected $errorMessageRegex; |
|
49 | ||
50 | /** |
|
51 | * Set the regular expression to match the entered value against |
|
52 | * |
|
53 | * @param string $regex |
|
54 | * |
|
55 | * @return MultiLineTextPagePart |
|
56 | */ |
|
57 | public function setRegex($regex) |
|
58 | { |
|
59 | $this->regex = $regex; |
|
60 | ||
61 | return $this; |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * Get the current regular expression |
|
66 | * |
|
67 | * @return string |
|
68 | */ |
|
69 | public function getRegex() |
|
70 | { |
|
71 | return $this->regex; |
|
72 | } |
|
73 | ||
74 | /** |
|
75 | * Set the error message which will be shown when the entered value doesn't match the regular expression |
|
76 | * |
|
77 | * @param string $errorMessageRegex |
|
78 | * |
|
79 | * @return MultiLineTextPagePart |
|
80 | */ |
|
81 | public function setErrorMessageRegex($errorMessageRegex) |
|
82 | { |
|
83 | $this->errorMessageRegex = $errorMessageRegex; |
|
84 | ||
85 | return $this; |
|
86 | } |
|
87 | ||
88 | /** |
|
89 | * Get the current error message which will be shown when the entered value doesn't match the regular expression |
|
90 | * |
|
91 | * @return string |
|
92 | */ |
|
93 | public function getErrorMessageRegex() |
|
94 | { |
|
95 | return $this->errorMessageRegex; |
|
96 | } |
|
97 | ||
98 | /** |
|
99 | * Returns the frontend view |
|
100 | * |
|
101 | * @return string |
|
102 | */ |
|
103 | public function getDefaultView() |
|
104 | { |
|
105 | return 'KunstmaanFormBundle:MultiLineTextPagePart:view.html.twig'; |
|
106 | } |
|
107 | ||
108 | /** |
|
109 | * Sets the required valud of this page part |
|
110 | * |
|
111 | * @param bool $required |
|
112 | * |
|
113 | * @return MultiLineTextPagePart |
|
114 | */ |
|
115 | public function setRequired($required) |
|
116 | { |
|
117 | $this->required = $required; |
|
118 | ||
119 | return $this; |
|
120 | } |
|
121 | ||
122 | /** |
|
123 | * Check if the page part is required |
|
124 | * |
|
125 | * @return bool |
|
126 | */ |
|
127 | public function getRequired() |
|
128 | { |
|
129 | return $this->required; |
|
130 | } |
|
131 | ||
132 | /** |
|
133 | * Sets the message shown when the page part is required and no value was entered |
|
134 | * |
|
135 | * @param string $errorMessageRequired |
|
136 | * |
|
137 | * @return MultiLineTextPagePart |
|
138 | */ |
|
139 | public function setErrorMessageRequired($errorMessageRequired) |
|
140 | { |
|
141 | $this->errorMessageRequired = $errorMessageRequired; |
|
142 | ||
143 | return $this; |
|
144 | } |
|
145 | ||
146 | /** |
|
147 | * Get the error message that will be shown when the page part is required and no value was entered |
|
148 | * |
|
149 | * @return string |
|
150 | */ |
|
151 | public function getErrorMessageRequired() |
|
152 | { |
|
153 | return $this->errorMessageRequired; |
|
154 | } |
|
155 | ||
156 | /** |
|
157 | * Modify the form with the fields of the current page part |
|
158 | * |
|
159 | * @param FormBuilderInterface $formBuilder The form builder |
|
160 | * @param ArrayObject $fields The fields |
|
161 | * @param int $sequence The sequence of the form field |
|
162 | */ |
|
163 | public function adaptForm(FormBuilderInterface $formBuilder, ArrayObject $fields, $sequence) |
|
164 | { |
|
165 | $mfsf = new TextFormSubmissionField(); |
|
166 | $mfsf->setFieldName('field_'.$this->getUniqueId()); |
|
167 | $mfsf->setLabel($this->getLabel()); |
|
168 | $mfsf->setSequence($sequence); |
|
169 | ||
170 | $data = $formBuilder->getData(); |
|
171 | $data['formwidget_'.$this->getUniqueId()] = $mfsf; |
|
172 | ||
173 | $constraints = []; |
|
174 | if ($this->getRequired()) { |
|
175 | $options = []; |
|
176 | if (!empty($this->errorMessageRequired)) { |
|
177 | $options['message'] = $this->errorMessageRequired; |
|
178 | } |
|
179 | $constraints[] = new NotBlank($options); |
|
180 | } |
|
181 | if ($this->getRegex()) { |
|
182 | $options = ['pattern' => $this->getRegex()]; |
|
183 | if (!empty($this->errorMessageRegex)) { |
|
184 | $options['message'] = $this->errorMessageRegex; |
|
185 | } |
|
186 | $constraints[] = new Regex($options); |
|
187 | } |
|
188 | ||
189 | $formBuilder->add( |
|
190 | 'formwidget_'.$this->getUniqueId(), |
|
191 | TextFormSubmissionType::class, |
|
192 | [ |
|
193 | 'label' => $this->getLabel(), |
|
194 | 'value_constraints' => $constraints, |
|
195 | 'required' => $this->getRequired(), |
|
196 | ] |
|
197 | ); |
|
198 | $formBuilder->setData($data); |
|
199 | ||
200 | $fields->append($mfsf); |
|
201 | } |
|
202 | ||
203 | /** |
|
204 | * Returns the default backend form type for this page part |
|
205 | * |
|
206 | * @return string |
|
207 | */ |
|
208 | public function getDefaultAdminType() |
|
209 | { |
|
210 | return MultiLineTextPagePartAdminType::class; |
|
211 | } |
|
212 | } |
|
213 |
@@ 20-211 (lines=192) @@ | ||
17 | * @ORM\Entity |
|
18 | * @ORM\Table(name="kuma_single_line_text_page_parts") |
|
19 | */ |
|
20 | class SingleLineTextPagePart extends AbstractFormPagePart |
|
21 | { |
|
22 | /** |
|
23 | * If set to true, you are obligated to fill in this page part |
|
24 | * |
|
25 | * @ORM\Column(type="boolean", nullable=true) |
|
26 | */ |
|
27 | protected $required = false; |
|
28 | ||
29 | /** |
|
30 | * Error message shows when the page part is required and nothing is filled in |
|
31 | * |
|
32 | * @ORM\Column(type="string", name="error_message_required", nullable=true) |
|
33 | */ |
|
34 | protected $errorMessageRequired; |
|
35 | ||
36 | /** |
|
37 | * If set the entered value will be matched with this regular expression |
|
38 | * |
|
39 | * @ORM\Column(type="string", nullable=true) |
|
40 | */ |
|
41 | protected $regex; |
|
42 | ||
43 | /** |
|
44 | * If a regular expression is set and it doesn't match with the given value, this error message will be shown |
|
45 | * |
|
46 | * @ORM\Column(type="string", name="error_message_regex", nullable=true) |
|
47 | */ |
|
48 | protected $errorMessageRegex; |
|
49 | ||
50 | /** |
|
51 | * Sets the required valud of this page part |
|
52 | * |
|
53 | * @param bool $required |
|
54 | * |
|
55 | * @return SingleLineTextPagePart |
|
56 | */ |
|
57 | public function setRequired($required) |
|
58 | { |
|
59 | $this->required = $required; |
|
60 | ||
61 | return $this; |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * Check if the page part is required |
|
66 | * |
|
67 | * @return bool |
|
68 | */ |
|
69 | public function getRequired() |
|
70 | { |
|
71 | return $this->required; |
|
72 | } |
|
73 | ||
74 | /** |
|
75 | * Sets the message shown when the page part is required and no value was entered |
|
76 | * |
|
77 | * @param string $errorMessageRequired |
|
78 | * |
|
79 | * @return SingleLineTextPagePart |
|
80 | */ |
|
81 | public function setErrorMessageRequired($errorMessageRequired) |
|
82 | { |
|
83 | $this->errorMessageRequired = $errorMessageRequired; |
|
84 | ||
85 | return $this; |
|
86 | } |
|
87 | ||
88 | /** |
|
89 | * Get the error message that will be shown when the page part is required and no value was entered |
|
90 | * |
|
91 | * @return string |
|
92 | */ |
|
93 | public function getErrorMessageRequired() |
|
94 | { |
|
95 | return $this->errorMessageRequired; |
|
96 | } |
|
97 | ||
98 | /** |
|
99 | * Set the regular expression to match the entered value against |
|
100 | * |
|
101 | * @param string $regex |
|
102 | * |
|
103 | * @return SingleLineTextPagePart |
|
104 | */ |
|
105 | public function setRegex($regex) |
|
106 | { |
|
107 | $this->regex = $regex; |
|
108 | ||
109 | return $this; |
|
110 | } |
|
111 | ||
112 | /** |
|
113 | * Get the current regular expression |
|
114 | * |
|
115 | * @return string |
|
116 | */ |
|
117 | public function getRegex() |
|
118 | { |
|
119 | return $this->regex; |
|
120 | } |
|
121 | ||
122 | /** |
|
123 | * Set the error message which will be shown when the entered value doesn't match the regular expression |
|
124 | * |
|
125 | * @param string $errorMessageRegex |
|
126 | * |
|
127 | * @return SingleLineTextPagePart |
|
128 | */ |
|
129 | public function setErrorMessageRegex($errorMessageRegex) |
|
130 | { |
|
131 | $this->errorMessageRegex = $errorMessageRegex; |
|
132 | ||
133 | return $this; |
|
134 | } |
|
135 | ||
136 | /** |
|
137 | * Get the current error message which will be shown when the entered value doesn't match the regular expression |
|
138 | * |
|
139 | * @return string |
|
140 | */ |
|
141 | public function getErrorMessageRegex() |
|
142 | { |
|
143 | return $this->errorMessageRegex; |
|
144 | } |
|
145 | ||
146 | /** |
|
147 | * Returns the frontend view |
|
148 | * |
|
149 | * @return string |
|
150 | */ |
|
151 | public function getDefaultView() |
|
152 | { |
|
153 | return 'KunstmaanFormBundle:SingleLineTextPagePart:view.html.twig'; |
|
154 | } |
|
155 | ||
156 | /** |
|
157 | * Modify the form with the fields of the current page part |
|
158 | * |
|
159 | * @param FormBuilderInterface $formBuilder The form builder |
|
160 | * @param ArrayObject $fields The fields |
|
161 | * @param int $sequence The sequence of the form field |
|
162 | */ |
|
163 | public function adaptForm(FormBuilderInterface $formBuilder, ArrayObject $fields, $sequence) |
|
164 | { |
|
165 | $sfsf = new StringFormSubmissionField(); |
|
166 | $sfsf->setFieldName('field_'.$this->getUniqueId()); |
|
167 | $sfsf->setLabel($this->getLabel()); |
|
168 | $sfsf->setSequence($sequence); |
|
169 | ||
170 | $data = $formBuilder->getData(); |
|
171 | $data['formwidget_'.$this->getUniqueId()] = $sfsf; |
|
172 | ||
173 | $constraints = []; |
|
174 | if ($this->getRequired()) { |
|
175 | $options = []; |
|
176 | if (!empty($this->errorMessageRequired)) { |
|
177 | $options['message'] = $this->errorMessageRequired; |
|
178 | } |
|
179 | $constraints[] = new NotBlank($options); |
|
180 | } |
|
181 | if ($this->getRegex()) { |
|
182 | $options = ['pattern' => $this->getRegex()]; |
|
183 | if (!empty($this->errorMessageRegex)) { |
|
184 | $options['message'] = $this->errorMessageRegex; |
|
185 | } |
|
186 | $constraints[] = new Regex($options); |
|
187 | } |
|
188 | ||
189 | $formBuilder->add( |
|
190 | 'formwidget_'.$this->getUniqueId(), |
|
191 | StringFormSubmissionType::class, |
|
192 | [ |
|
193 | 'label' => $this->getLabel(), |
|
194 | 'value_constraints' => $constraints, |
|
195 | 'required' => $this->getRequired(), |
|
196 | ] |
|
197 | ); |
|
198 | $formBuilder->setData($data); |
|
199 | ||
200 | $fields->append($sfsf); |
|
201 | } |
|
202 | ||
203 | /** |
|
204 | * Returns the default backend form type for this page part |
|
205 | * |
|
206 | * @return string |
|
207 | */ |
|
208 | public function getDefaultAdminType() |
|
209 | { |
|
210 | return SingleLineTextPagePartAdminType::class; |
|
211 | } |
|
212 | } |
|
213 |