|
@@ 98-157 (lines=60) @@
|
| 95 |
|
* |
| 96 |
|
* @return Response|RedirectResponse |
| 97 |
|
*/ |
| 98 |
|
public function crudCreateObject(Request $request, array $templateVars = array()) |
| 99 |
|
{ |
| 100 |
|
$crudCreateRole = $this->crudCreateRole(); |
| 101 |
|
if (!$this->crudIsGranted($crudCreateRole)) { |
| 102 |
|
throw new AccessDeniedException(sprintf('You need the permission to create an object, role: %s!', $crudCreateRole)); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
$object = $this->crudCreateFactory($request); |
| 106 |
|
$form = $this->crudCreateForm($object, $request); |
| 107 |
|
|
| 108 |
|
if ('POST' === $request->getMethod()) { |
| 109 |
|
$form->handleRequest($request); |
| 110 |
|
if ($this->crudCreateIsSubmitted($object, $form, $request)) { |
| 111 |
|
if ($form->isValid()) { |
| 112 |
|
$this->crudCreatePrePersist($object, $form, $request); |
| 113 |
|
|
| 114 |
|
$em = $this->crudManagerForClass($this->crudObjectClass()); |
| 115 |
|
$em->persist($object); |
| 116 |
|
$em->flush(); |
| 117 |
|
|
| 118 |
|
$this->crudCreatePostFlush($object, $form, $request); |
| 119 |
|
$this->crudCreateSuccessFlashMesssage($object, $form, $request); |
| 120 |
|
$response = $this->crudCreateSuccessResponse($object, $form, $request); |
| 121 |
|
} else { |
| 122 |
|
$this->crudCreateErrorFlashMesssage($object, $form, $request); |
| 123 |
|
$response = $this->crudCreateErrorResponse($object, $form, $request); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
if (null !== $response) { |
| 127 |
|
return $response; |
| 128 |
|
} |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
$baseTemplateVars = array( |
| 133 |
|
'request' => $request, |
| 134 |
|
'object' => $object, |
| 135 |
|
'form' => $form->createView(), |
| 136 |
|
'createRoute' => $this->crudCreateRoute(), |
| 137 |
|
'listRoute' => $this->crudListRoute(), |
| 138 |
|
'editRoute' => $this->crudEditRoute(), |
| 139 |
|
'viewRoute' => $this->crudViewRoute(), |
| 140 |
|
'deleteRoute' => $this->crudDeleteRoute(), |
| 141 |
|
'listRole' => $this->crudListRole(), |
| 142 |
|
'createRole' => $this->crudCreateRole(), |
| 143 |
|
'editRole' => $this->crudEditRole(), |
| 144 |
|
'viewRole' => $this->crudViewRole(), |
| 145 |
|
'deleteRole' => $this->crudDeleteRole(), |
| 146 |
|
'identifier' => $this->crudIdentifier(), |
| 147 |
|
'transPrefix' => $this->crudTransPrefix(), |
| 148 |
|
'transDomain' => $this->crudTransDomain(), |
| 149 |
|
'objectClass' => $this->crudObjectClass(), |
| 150 |
|
); |
| 151 |
|
|
| 152 |
|
return $this->crudCreateRenderTemplateResponse( |
| 153 |
|
$request, |
| 154 |
|
$baseTemplateVars, |
| 155 |
|
$templateVars |
| 156 |
|
); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
/** |
| 160 |
|
* @param Request $request |
|
@@ 166-226 (lines=61) @@
|
| 163 |
|
* |
| 164 |
|
* @return Response|RedirectResponse |
| 165 |
|
*/ |
| 166 |
|
public function crudEditObject(Request $request, $object, array $templateVars = array()) |
| 167 |
|
{ |
| 168 |
|
$object = $this->crudEditLoadObject($object, $request); |
| 169 |
|
|
| 170 |
|
$crudEditRole = $this->crudEditRole(); |
| 171 |
|
if (!$this->crudIsGranted($crudEditRole, $object)) { |
| 172 |
|
throw new AccessDeniedException(sprintf('You need the permission to edit this object, role: %s!', $crudEditRole)); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
$form = $this->crudEditForm($object, $request); |
| 176 |
|
|
| 177 |
|
if ('POST' === $request->getMethod()) { |
| 178 |
|
$form->handleRequest($request); |
| 179 |
|
if ($this->crudEditIsSubmitted($object, $form, $request)) { |
| 180 |
|
if ($form->isValid()) { |
| 181 |
|
$this->crudEditPrePersist($object, $form, $request); |
| 182 |
|
|
| 183 |
|
$em = $this->crudManagerForClass($this->crudObjectClass()); |
| 184 |
|
$em->persist($object); |
| 185 |
|
$em->flush(); |
| 186 |
|
|
| 187 |
|
$this->crudEditPostFlush($object, $form, $request); |
| 188 |
|
$this->crudEditSuccessFlashMesssage($object, $form, $request); |
| 189 |
|
$response = $this->crudEditSuccessResponse($object, $form, $request); |
| 190 |
|
} else { |
| 191 |
|
$this->crudEditErrorFlashMesssage($object, $form, $request); |
| 192 |
|
$response = $this->crudEditErrorResponse($object, $form, $request); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
if (null !== $response) { |
| 196 |
|
return $response; |
| 197 |
|
} |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
$baseTemplateVars = array( |
| 202 |
|
'request' => $request, |
| 203 |
|
'object' => $object, |
| 204 |
|
'form' => $form->createView(), |
| 205 |
|
'createRoute' => $this->crudCreateRoute(), |
| 206 |
|
'listRoute' => $this->crudListRoute(), |
| 207 |
|
'editRoute' => $this->crudEditRoute(), |
| 208 |
|
'viewRoute' => $this->crudViewRoute(), |
| 209 |
|
'deleteRoute' => $this->crudDeleteRoute(), |
| 210 |
|
'listRole' => $this->crudListRole(), |
| 211 |
|
'createRole' => $this->crudCreateRole(), |
| 212 |
|
'editRole' => $this->crudEditRole(), |
| 213 |
|
'viewRole' => $this->crudViewRole(), |
| 214 |
|
'deleteRole' => $this->crudDeleteRole(), |
| 215 |
|
'identifier' => $this->crudIdentifier(), |
| 216 |
|
'transPrefix' => $this->crudTransPrefix(), |
| 217 |
|
'transDomain' => $this->crudTransDomain(), |
| 218 |
|
'objectClass' => $this->crudObjectClass(), |
| 219 |
|
); |
| 220 |
|
|
| 221 |
|
return $this->crudEditRenderTemplateResponse( |
| 222 |
|
$request, |
| 223 |
|
$baseTemplateVars, |
| 224 |
|
$templateVars |
| 225 |
|
); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
/** |
| 229 |
|
* @param Request $request |