@@ 20-140 (lines=121) @@ | ||
17 | * @ORM\Entity |
|
18 | * @ORM\Table(name="kuma_checkbox_page_parts") |
|
19 | */ |
|
20 | class CheckboxPagePart 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 | * Sets the required valud of this page part |
|
38 | * |
|
39 | * @param bool $required |
|
40 | * |
|
41 | * @return CheckboxPagePart |
|
42 | */ |
|
43 | public function setRequired($required) |
|
44 | { |
|
45 | $this->required = $required; |
|
46 | ||
47 | return $this; |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * Check if the page part is required |
|
52 | * |
|
53 | * @return bool |
|
54 | */ |
|
55 | public function getRequired() |
|
56 | { |
|
57 | return $this->required; |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * Sets the message shown when the page part is required and no value was entered |
|
62 | * |
|
63 | * @param string $errorMessageRequired |
|
64 | * |
|
65 | * @return CheckboxPagePart |
|
66 | */ |
|
67 | public function setErrorMessageRequired($errorMessageRequired) |
|
68 | { |
|
69 | $this->errorMessageRequired = $errorMessageRequired; |
|
70 | ||
71 | return $this; |
|
72 | } |
|
73 | ||
74 | /** |
|
75 | * Get the error message that will be shown when the page part is required and no value was entered |
|
76 | * |
|
77 | * @return string |
|
78 | */ |
|
79 | public function getErrorMessageRequired() |
|
80 | { |
|
81 | return $this->errorMessageRequired; |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * Returns the frontend view |
|
86 | * |
|
87 | * @return string |
|
88 | */ |
|
89 | public function getDefaultView() |
|
90 | { |
|
91 | return "KunstmaanFormBundle:CheckboxPagePart:view.html.twig"; |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * Modify the form with the fields of the current page part |
|
96 | * |
|
97 | * @param FormBuilderInterface $formBuilder The form builder |
|
98 | * @param ArrayObject $fields The fields |
|
99 | * @param int $sequence The sequence of the form field |
|
100 | */ |
|
101 | public function adaptForm(FormBuilderInterface $formBuilder, ArrayObject $fields, $sequence) |
|
102 | { |
|
103 | $bfsf = new BooleanFormSubmissionField(); |
|
104 | $bfsf->setFieldName('field_' . $this->getUniqueId()); |
|
105 | $bfsf->setLabel($this->getLabel()); |
|
106 | $bfsf->setSequence($sequence); |
|
107 | ||
108 | $data = $formBuilder->getData(); |
|
109 | $data['formwidget_' . $this->getUniqueId()] = $bfsf; |
|
110 | $constraints = array(); |
|
111 | if ($this->getRequired()) { |
|
112 | $options = array(); |
|
113 | if (!empty($this->errorMessageRequired)) { |
|
114 | $options['message'] = $this->errorMessageRequired; |
|
115 | } |
|
116 | $constraints[] = new NotBlank($options); |
|
117 | } |
|
118 | $formBuilder->add('formwidget_' . $this->getUniqueId(), |
|
119 | BooleanFormSubmissionType::class, |
|
120 | array( |
|
121 | 'label' => $this->getLabel(), |
|
122 | 'constraints' => $constraints, |
|
123 | 'required' => $this->getRequired() |
|
124 | ) |
|
125 | ); |
|
126 | $formBuilder->setData($data); |
|
127 | ||
128 | $fields->append($bfsf); |
|
129 | } |
|
130 | ||
131 | /** |
|
132 | * Returns the default backend form type for this page part |
|
133 | * |
|
134 | * @return string |
|
135 | */ |
|
136 | public function getDefaultAdminType() |
|
137 | { |
|
138 | return CheckboxPagePartAdminType::class; |
|
139 | } |
|
140 | } |
|
141 |
@@ 20-143 (lines=124) @@ | ||
17 | * @ORM\HasLifecycleCallbacks |
|
18 | * @ORM\Table(name="kuma_file_upload_page_parts") |
|
19 | */ |
|
20 | class FileUploadPagePart 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 | * Modify the form with the fields of the current page part |
|
38 | * |
|
39 | * @param FormBuilderInterface $formBuilder The form builder |
|
40 | * @param ArrayObject $fields The fields |
|
41 | * @param int $sequence The sequence of the form field |
|
42 | */ |
|
43 | public function adaptForm(FormBuilderInterface $formBuilder, ArrayObject $fields, $sequence) |
|
44 | { |
|
45 | $ffsf = new FileFormSubmissionField(); |
|
46 | $ffsf->setFieldName('field_' . $this->getUniqueId()); |
|
47 | $ffsf->setLabel($this->getLabel()); |
|
48 | $ffsf->setSequence($sequence); |
|
49 | ||
50 | $data = $formBuilder->getData(); |
|
51 | $data['formwidget_' . $this->getUniqueId()] = $ffsf; |
|
52 | ||
53 | $constraints = array(); |
|
54 | if ($this->getRequired()) { |
|
55 | $options = array(); |
|
56 | if (!empty($this->errorMessageRequired)) { |
|
57 | $options['message'] = $this->errorMessageRequired; |
|
58 | } |
|
59 | $constraints[] = new NotBlank($options); |
|
60 | } |
|
61 | ||
62 | $formBuilder->add( |
|
63 | 'formwidget_' . $this->getUniqueId(), |
|
64 | FileFormSubmissionType::class, |
|
65 | array( |
|
66 | 'label' => $this->getLabel(), |
|
67 | 'constraints' => $constraints, |
|
68 | 'required' => $this->getRequired() |
|
69 | ) |
|
70 | ); |
|
71 | $formBuilder->setData($data); |
|
72 | ||
73 | $fields->append($ffsf); |
|
74 | } |
|
75 | ||
76 | /** |
|
77 | * Sets the required valud of this page part |
|
78 | * |
|
79 | * @param bool $required |
|
80 | * |
|
81 | * @return FileUploadPagePart |
|
82 | */ |
|
83 | public function setRequired($required) |
|
84 | { |
|
85 | $this->required = $required; |
|
86 | ||
87 | return $this; |
|
88 | } |
|
89 | ||
90 | /** |
|
91 | * Check if the page part is required |
|
92 | * |
|
93 | * @return bool |
|
94 | */ |
|
95 | public function getRequired() |
|
96 | { |
|
97 | return $this->required; |
|
98 | } |
|
99 | ||
100 | /** |
|
101 | * Sets the message shown when the page part is required and no value was entered |
|
102 | * |
|
103 | * @param string $errorMessageRequired |
|
104 | * |
|
105 | * @return FileUploadPagePart |
|
106 | */ |
|
107 | public function setErrorMessageRequired($errorMessageRequired) |
|
108 | { |
|
109 | $this->errorMessageRequired = $errorMessageRequired; |
|
110 | ||
111 | return $this; |
|
112 | } |
|
113 | ||
114 | /** |
|
115 | * Get the error message that will be shown when the page part is required and no value was entered |
|
116 | * |
|
117 | * @return string |
|
118 | */ |
|
119 | public function getErrorMessageRequired() |
|
120 | { |
|
121 | return $this->errorMessageRequired; |
|
122 | } |
|
123 | ||
124 | /** |
|
125 | * Returns the view used in the frontend |
|
126 | * |
|
127 | * @return mixed |
|
128 | */ |
|
129 | public function getDefaultView() |
|
130 | { |
|
131 | return "KunstmaanFormBundle:FileUploadPagePart:view.html.twig"; |
|
132 | } |
|
133 | ||
134 | /** |
|
135 | * Returns the default backend form type for this page part |
|
136 | * |
|
137 | * @return string |
|
138 | */ |
|
139 | public function getDefaultAdminType() |
|
140 | { |
|
141 | return FileUploadPagePartAdminType::class; |
|
142 | } |
|
143 | } |
|
144 |