/**
* Edit and Saves category
*
* @param FormInterface $form Form
* @param CarrierInterface $carrier Carrier
* @param ShippingRangeInterface $shippingRange Shipping range
* @param boolean $isValid Is valid
*
* @return RedirectResponse Redirect response
*
* @Route(
* path = "/{id}",
* name = "admin_shipping_range_edit",
* requirements = {
* "id" = "\d+",
* },
* methods = {"GET"}
* )
* @Route(
* path = "/{id}/update",
* name = "admin_shipping_range_update",
* requirements = {
* "id" = "\d+",
* },
* methods = {"POST"}
* )
*
* @Route(
* path = "/new",
* name = "admin_shipping_range_new",
* methods = {"GET"}
* )
* @Route(
* path = "/new/update",
* name = "admin_shipping_range_save",
* methods = {"POST"}
* )
*
* @EntityAnnotation(
* class = "elcodi.entity.carrier.class",
* mapping = {
* "id" = "~carrierId~"
* },
* name = "carrier"
* )
* @EntityAnnotation(
* class = {
* "factory" = "elcodi_plugin.custom_shipping.factory.shipping_range",
* "method" = "create",
* "static" = false
* },
* mapping = {
* "id" = "~id~"
* },
* mappingFallback = true,
* name = "shippingRange",
* persist = true
* )
* @FormAnnotation(
* class = "elcodi_plugin_custom_shipping_form_type_shipping_range",
* name = "form",
* entity = "shippingRange",
* handleRequest = true,
* validate = "isValid"
* )
*
* @Template
*/
public function editAction(FormInterface $form, CarrierInterface $carrier, ShippingRangeInterface $shippingRange, $isValid)
{
if ($isValid) {
/**
* We must add the default Carrier
*/
$shippingRange->setCarrier($carrier);
$this->flush($shippingRange);
$this->addFlash('success', $this->get('translator')->trans('admin.shipping_range.saved'));
return $this->redirectToRoute('admin_carrier_edit', ['id' => $carrier->getId()]);
}
return ['shippingRange' => $shippingRange, 'carrier' => $carrier, 'form' => $form->createView()];
}