Code Duplication    Length = 43-47 lines in 2 locations

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

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