postalCodeRepository = $postalCodeRepository; } /** * @param null $value */ public function loadChoiceList($value = null): ChoiceListInterface { return new \Symfony\Component\Form\ChoiceList\ArrayChoiceList( $this->lazyLoadedPostalCodes, static function (?PostalCode $pc = null) use ($value) { return call_user_func($value, $pc); } ); } /** * @param null $value * * @return array */ public function loadChoicesForValues(array $values, $value = null) { $choices = []; foreach ($values as $value) { if (empty($value)) { $choices[] = null; } else { $choices[] = $this->postalCodeRepository->find($value); } } return $choices; } /** * @param null $value * * @return array|string[] */ public function loadValuesForChoices(array $choices, $value = null) { $values = []; foreach ($choices as $choice) { if (null === $choice) { $values[] = null; continue; } $id = call_user_func($value, $choice); $values[] = $id; $this->lazyLoadedPostalCodes[$id] = $choice; } return $values; } }