Code Duplication    Length = 43-46 lines in 2 locations

src/Kunstmaan/AdminListBundle/Controller/AdminListController.php 2 locations

@@ 127-169 (lines=43) @@
124
125
        $form = $this->createForm($formType, $helper, $event->getOptions());
126
127
        if ($request->isMethod('POST')) {
128
            if ($tabPane) {
129
                $tabPane->bindRequest($request);
130
                $form = $tabPane->getForm();
131
            } else {
132
                $form->handleRequest($request);
133
            }
134
135
            // Don't redirect to listing when coming from ajax request, needed for url chooser.
136
            if ($form->isSubmitted() && $form->isValid() && !$request->isXmlHttpRequest()) {
137
                $adminListEvent = new AdminListEvent($helper, $request, $form);
138
                $this->dispatch(
139
                    $adminListEvent,
140
                    AdminListEvents::PRE_ADD
141
                );
142
143
                // Check if Response is given
144
                if ($adminListEvent->getResponse() instanceof Response) {
145
                    return $adminListEvent->getResponse();
146
                }
147
148
                // Set sort weight
149
                $helper = $this->setSortWeightOnNewItem($configurator, $helper);
150
151
                $em->persist($helper);
152
                $em->flush();
153
                $this->dispatch(
154
                    $adminListEvent,
155
                    AdminListEvents::POST_ADD
156
                );
157
158
                // Check if Response is given
159
                if ($adminListEvent->getResponse() instanceof Response) {
160
                    return $adminListEvent->getResponse();
161
                }
162
163
                $indexUrl = $configurator->getIndexUrl();
164
165
                return new RedirectResponse(
166
                    $this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array())
167
                );
168
            }
169
        }
170
171
        $params = [
172
            'form' => $form->createView(),
@@ 245-290 (lines=46) @@
242
243
        $form = $this->createForm($formType, $helper, $event->getOptions());
244
245
        if ($request->isMethod('POST')) {
246
            if ($tabPane) {
247
                $tabPane->bindRequest($request);
248
                $form = $tabPane->getForm();
249
            } else {
250
                $form->handleRequest($request);
251
            }
252
253
            // Don't redirect to listing when coming from ajax request, needed for url chooser.
254
            if ($form->isSubmitted() && $form->isValid() && !$request->isXmlHttpRequest()) {
255
                $adminListEvent = new AdminListEvent($helper, $request, $form);
256
                $this->dispatch(
257
                    $adminListEvent,
258
                    AdminListEvents::PRE_EDIT
259
                );
260
261
                // Check if Response is given
262
                if ($adminListEvent->getResponse() instanceof Response) {
263
                    return $adminListEvent->getResponse();
264
                }
265
266
                $em->persist($helper);
267
                $em->flush();
268
                $this->dispatch(
269
                    $adminListEvent,
270
                    AdminListEvents::POST_EDIT
271
                );
272
273
                // Check if Response is given
274
                if ($adminListEvent->getResponse() instanceof Response) {
275
                    return $adminListEvent->getResponse();
276
                }
277
278
                $indexUrl = $configurator->getIndexUrl();
279
280
                // Don't redirect to listing when coming from ajax request, needed for url chooser.
281
                if (!$request->isXmlHttpRequest()) {
282
                    return new RedirectResponse(
283
                        $this->generateUrl(
284
                            $indexUrl['path'],
285
                            isset($indexUrl['params']) ? $indexUrl['params'] : array()
286
                        )
287
                    );
288
                }
289
            }
290
        }
291
292
        $configurator->buildItemActions();
293