Code Duplication    Length = 43-47 lines in 2 locations

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

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