Code Duplication    Length = 43-47 lines in 2 locations

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

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