private function createFields() { $shipmentOptions = []; $personalPoints = $this->shipmentService->getPersonalPoints(); foreach ($personalPoints as $personalPoint) { $key = sprintf('%d-%d', ShipmentType::PERSONAL, $personalPoint->getId()); $shipmentOptions[$key] = sprintf('Personally at: %s', $this->shipmentHelper->formatShipmentOption($personalPoint)); } $collectionPoints = $this->shipmentService->getCollectionPoints(); foreach ($collectionPoints as $collectionPoint) { $key = sprintf('%d-%d', ShipmentType::TO_COLLECTION_POINT, $collectionPoint->getId()); $shipmentOptions[$key] = sprintf('At collection point: %s', $this->shipmentHelper->formatShipmentOption($collectionPoint)); } $transportCompanies = $this->shipmentService->getTransportCompanies(); $transportCompanyKeys = []; $hasTransportCompany = false; foreach ($transportCompanies as $transportCompany) { $key = sprintf('%d-%d', ShipmentType::BY_TRANSPORT_COMPANY, $transportCompany->getId()); $shipmentOptions[$key] = $this->shipmentHelper->formatShipmentOption($transportCompany); $transportCompanyKeys[] = $key; $hasTransportCompany = true; } $shipmentControl = $this->addRadioList('shipment', 'Shipment', $shipmentOptions)->setDefaultValue(key($shipmentOptions))->setRequired(); if ($this->shipment !== null) { $shipmentControl->setDefaultValue(sprintf('%d-%d', $this->shipment->getShipmentOption()->getType()->getValue(), $this->shipment->getShipmentOption()->getId())); } $defaultName = null; $defaultStreet = null; $defaultCity = null; $defaultZip = null; if ($this->shipment instanceof ShipmentByTransportCompany) { $defaultName = $this->shipment->getName(); $defaultStreet = $this->shipment->getStreet(); $defaultCity = $this->shipment->getCity(); $defaultZip = $this->shipment->getZip(); } elseif ($this->user !== null) { $defaultName = $this->user->getName(); $defaultStreet = $this->user->getStreet(); $defaultCity = $this->user->getCity(); $defaultZip = $this->user->getZip(); } if ($hasTransportCompany) { $requiring = function (TextInput $control) use($shipmentControl, $transportCompanyKeys) { return $control->addConditionOn($shipmentControl, self::IS_IN, $transportCompanyKeys); }; $addressContainer = new AddressFormContainer(); $this->addComponent($addressContainer, 'address'); $addressContainer->addNameControl('name', $defaultName, $requiring); $addressContainer->addStreetControl('street', $defaultStreet, $requiring); $addressContainer->addCityControl('city', $defaultCity, $requiring); $addressContainer->addZipControl('zip', $defaultZip, $requiring); $shipmentControl->addCondition(self::IS_IN, $transportCompanyKeys)->toggle('order-shipment-address'); } $this->addSubmit('next', 'Next'); }
public function formatShipmentOption(ShipmentOption $option) { return $this->shipmentHelper->formatShipmentOption($option); }