/** * @param Request $request * @param string $id * * @return \Symfony\Component\HttpFoundation\Response */ public function deleteAction(Request $request, $id) { $data = $this->manager->find($id); // It should always be possible to delete a connector even if the adaptor itself does // not exist anymore. So unlike the new and edit actions this action will not throw a // not found exception when the adaptor does not exist. if (!$data) { return $this->redirect($this->generateUrl('integrated_channel_config_index')); // data is already gone } $form = $this->createDeleteForm($data); if ($request->isMethod('delete')) { $form->handleRequest($request); if ($form->get('actions')->getData() == 'cancel') { return $this->redirect($this->generateUrl('integrated_channel_config_index')); } if ($form->isValid()) { $this->manager->remove($data); if ($message = $this->getFlashMessage()) { $message->success(sprintf('The config %s is removed', $data->getName())); } return $this->redirect($this->generateUrl('integrated_channel_config_index')); } } return $this->render('IntegratedChannelBundle:Config:delete.html.twig', ['adapter' => $this->registry->hasAdapter($data->getAdapter()) ? $this->registry->getAdapter($data->getAdapter()) : null, 'data' => $data, 'form' => $form->createView()]); }
/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $adapterNormalizer = function (Options $options, $adapter) { if (is_string($adapter)) { try { $adapter = $this->registry->getAdapter($adapter); } catch (Exception $e) { $adapter = null; } } if (!$adapter instanceof AdapterInterface) { throw new InvalidOptionsException(sprintf('The option "%s" could not be normalized to a valid "%s" object', 'adapter', 'Integrated\\Common\\Channel\\Connector\\AdapterInterface')); } return $adapter; }; $resolver->setRequired('adapter'); $resolver->setAllowedTypes('adapter', ['string', 'Integrated\\Common\\Channel\\Connector\\AdapterInterface']); $resolver->setNormalizer('adapter', $adapterNormalizer); $resolver->setDefault('data_class', 'Integrated\\Bundle\\ChannelBundle\\Model\\Config'); }