/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $choiceList = function (Options $options) { if (isset($options['subject'])) { $methods = $this->resolver->getSupportedMethods($options['subject'], $options['criteria']); } else { $methods = $this->repository->findBy($options['criteria']); } if ($options['channel']) { $filteredMethods = []; foreach ($methods as $method) { if ($options['channel']->hasShippingMethod($method)) { $filteredMethods[] = $method; } } $methods = $filteredMethods; } return new ObjectChoiceList($methods, null, [], null, 'id'); }; $resolver->setDefaults(['choice_list' => $choiceList, 'criteria' => [], 'channel' => null])->setAllowedTypes('channel', [ChannelInterface::class, 'null']); }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { parent::setDefaultOptions($resolver); $methodsResolver = $this->resolver; $repository = $this->repository; $choiceList = function (Options $options) use($methodsResolver, $repository) { if (isset($options['subject'])) { $methods = $methodsResolver->getSupportedMethods($options['subject'], $options['criteria']); } else { $methods = $repository->findBy($options['criteria']); } if ($options['channel']) { $filteredMethods = array(); foreach ($methods as $method) { if ($options['channel']->hasShippingMethod($method)) { $filteredMethods[] = $method; } } $methods = $filteredMethods; } return new ObjectChoiceList($methods); }; $resolver->setDefaults(array('choice_list' => $choiceList, 'criteria' => array(), 'channel' => null))->setAllowedTypes(array('channel' => array('Sylius\\Component\\Channel\\Model\\ChannelInterface', 'null'))); }