Code Duplication    Length = 43-47 lines in 2 locations

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

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