Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge 2.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Apr 4, 2017
2 parents c3dd9bf + caa91d9 commit acd31fc
Show file tree
Hide file tree
Showing 22 changed files with 362 additions and 71 deletions.
48 changes: 42 additions & 6 deletions src/BasketBundle/Controller/BasketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class BasketController extends Controller
*/
public function indexAction($form = null)
{
$form = $form ?: $this->createForm('sonata_basket_basket', $this->get('sonata.basket'), array(
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$basketFormType = 'Sonata\BasketBundle\Form\BasketType';
} else {
$basketFormType = 'sonata_basket_basket';
}
$form = $form ?: $this->createForm($basketFormType, $this->get('sonata.basket'), array(
'validation_groups' => array('elements'),
));

Expand Down Expand Up @@ -67,7 +73,13 @@ public function indexAction($form = null)
*/
public function updateAction()
{
$form = $this->createForm('sonata_basket_basket', $this->get('sonata.basket'), array('validation_groups' => array('elements')));
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$basketFormType = 'Sonata\BasketBundle\Form\BasketType';
} else {
$basketFormType = 'sonata_basket_basket';
}
$form = $this->createForm($basketFormType, $this->get('sonata.basket'), array('validation_groups' => array('elements')));
$form->handleRequest($this->get('request'));

if ($form->isValid()) {
Expand Down Expand Up @@ -233,7 +245,13 @@ public function paymentStepAction()
$basket->setBillingAddress($billingAddress);
}

$form = $this->createForm('sonata_basket_payment', $basket, array(
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$paymentFormType = 'Sonata\BasketBundle\Form\PaymentType';
} else {
$paymentFormType = 'sonata_basket_payment';
}
$form = $this->createForm($paymentFormType, $basket, array(
'validation_groups' => array('delivery'),
));

Expand Down Expand Up @@ -279,7 +297,13 @@ public function deliveryStepAction()
}

try {
$form = $this->createForm('sonata_basket_shipping', $basket, array(
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$shippingFormType = 'Sonata\BasketBundle\Form\ShippingType';
} else {
$shippingFormType = 'sonata_basket_shipping';
}
$form = $this->createForm($shippingFormType, $basket, array(
'validation_groups' => array('delivery'),
));
} catch (UndeliverableCountryException $ex) {
Expand Down Expand Up @@ -336,8 +360,14 @@ public function deliveryAddressStepAction()

$addresses = $customer->getAddressesByType(AddressInterface::TYPE_DELIVERY);

// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$addressFormType = 'Sonata\BasketBundle\Form\AddressType';
} else {
$addressFormType = 'sonata_basket_address';
}
// Show address creation / selection form
$form = $this->createForm('sonata_basket_address', null, array('addresses' => $addresses));
$form = $this->createForm($addressFormType, null, array('addresses' => $addresses));
$template = 'SonataBasketBundle:Basket:delivery_address_step.html.twig';

if ($this->get('request')->getMethod() == 'POST') {
Expand Down Expand Up @@ -401,8 +431,14 @@ public function paymentAddressStepAction()

$addresses = $customer->getAddressesByType(AddressInterface::TYPE_BILLING);

// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$addressFormType = 'Sonata\BasketBundle\Form\AddressType';
} else {
$addressFormType = 'sonata_basket_address';
}
// Show address creation / selection form
$form = $this->createForm('sonata_basket_address', null, array('addresses' => $addresses->toArray()));
$form = $this->createForm($addressFormType, null, array('addresses' => $addresses->toArray()));
$template = 'SonataBasketBundle:Basket:payment_address_step.html.twig';

if ($this->get('request')->getMethod() == 'POST') {
Expand Down
21 changes: 17 additions & 4 deletions src/BasketBundle/Form/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public function __construct($addressClass, BasketInterface $basket)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$entityType = 'Symfony\Bridge\Doctrine\Form\Type\EntityType';
$submitType = 'Symfony\Component\Form\Extension\Core\Type\SubmitType';
$choiceType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
$countryType = 'Symfony\Component\Form\Extension\Core\Type\CountryType';
} else {
$entityType = 'entity';
$submitType = 'submit';
$choiceType = 'choice';
$countryType = 'country';
}

$addresses = $options['addresses'];

if (count($addresses) > 0) {
Expand All @@ -63,15 +76,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
}

$builder->add('addresses', 'entity', array(
$builder->add('addresses', $entityType, array(
'choices' => $addresses,
'preferred_choices' => array($defaultAddress),
'class' => $this->addressClass,
'expanded' => true,
'multiple' => false,
'mapped' => false,
))
->add('useSelected', 'submit', array(
->add('useSelected', $submitType, array(
'attr' => array(
'class' => 'btn btn-primary',
'style' => 'margin-bottom:20px;',
Expand All @@ -84,7 +97,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add('name', null, array('required' => !count($addresses)));

if (isset($options['types'])) {
$builder->add('type', 'choice', array(
$builder->add('type', $choiceType, array(
'choices' => $options['types'],
'translation_domain' => 'SonataCustomerBundle', )
);
Expand Down Expand Up @@ -119,7 +132,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$countryOptions['choices'] = $countries;
}

$builder->add('countryCode', 'country', $countryOptions);
$builder->add('countryCode', $countryType, $countryOptions);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/BasketBundle/Form/ApiBasketElementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function getName()
*/
public function getParent()
{
return 'sonata_basket_api_form_basket_element_parent';
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Sonata\BasketBundle\Form\ApiBasketElementParentType'
: 'sonata_basket_api_form_basket_element_parent';
}
}
5 changes: 4 additions & 1 deletion src/BasketBundle/Form/ApiBasketType.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function getName()
*/
public function getParent()
{
return 'sonata_basket_api_form_basket_parent';
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Sonata\BasketBundle\Form\ApiBasketParentType'
: 'sonata_basket_api_form_basket_parent';
}
}
9 changes: 8 additions & 1 deletion src/BasketBundle/Form/BasketType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class BasketType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$formType = 'Symfony\Component\Form\Extension\Core\Type\FormType';
} else {
$formType = 'form';
}

// always clone the basket, so the one in session is never altered
$basket = $builder->getData();

Expand All @@ -31,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}

// should create a custom basket elements here
$basketElementBuilder = $builder->create('basketElements', 'form', array(
$basketElementBuilder = $builder->create('basketElements', $formType, array(
'by_reference' => false,
));
$basketElementBuilder->addEventSubscriber(new BasketResizeFormListener($builder->getFormFactory(), $basket));
Expand Down
9 changes: 8 additions & 1 deletion src/BasketBundle/Form/PaymentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public function __construct(AddressManagerInterface $addressManager, PaymentPool
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$choiceType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
} else {
$choiceType = 'choice';
}

$basket = $builder->getData();

if (!$basket instanceof BasketInterface) {
Expand Down Expand Up @@ -90,7 +97,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$method = $basket->getPaymentMethod() ?: current($methods);
$basket->setPaymentMethod($method ?: null);

$sub = $builder->create('paymentMethod', 'choice', array(
$sub = $builder->create('paymentMethod', $choiceType, array(
'expanded' => true,
'choice_list' => new SimpleChoiceList($choices),
));
Expand Down
9 changes: 8 additions & 1 deletion src/BasketBundle/Form/ShippingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public function __construct(DeliveryPool $deliveryPool, ServiceDeliverySelectorI
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$choiceType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
} else {
$choiceType = 'choice';
}

$basket = $builder->getData();

if (!$basket instanceof BasketInterface) {
Expand All @@ -69,7 +76,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$method = $basket->getDeliveryMethod() ?: current($methods);
$basket->setDeliveryMethod($method ?: null);

$sub = $builder->create('deliveryMethod', 'choice', array(
$sub = $builder->create('deliveryMethod', $choiceType, array(
'expanded' => true,
'choice_list' => new SimpleChoiceList($choices),
));
Expand Down
5 changes: 4 additions & 1 deletion src/Component/Form/Type/DeliveryChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function __construct(Pool $pool)
*/
public function getParent()
{
return 'choice';
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'
: 'choice';
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/Component/Form/Type/VariationChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ public function __construct(Pool $pool)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$choiceType = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
} else {
$choiceType = 'choice';
}

$choices = $this->pool->getProvider($options['product'])->getVariationsChoices($options['product'], $options['fields']);

foreach ($choices as $choiceTitle => $choiceValues) {
$builder->add($choiceTitle, 'choice', array_merge(
$builder->add($choiceTitle, $choiceType, array_merge(
array('translation_domain' => 'SonataProductBundle'),
$options['field_options'],
array(
Expand Down
35 changes: 30 additions & 5 deletions src/CustomerBundle/Admin/AddressAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public function configure()
*/
public function configureFormFields(FormMapper $formMapper)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$addressTypeType = 'Sonata\CustomerBundle\Form\Type\AddressTypeType';
$modelListType = 'Sonata\AdminBundle\Form\Type\ModelListType';
$countryType = 'Symfony\Component\Form\Extension\Core\Type\CountryType';
} else {
$addressTypeType = 'sonata_customer_address_types';
$modelListType = 'sonata_type_model_list';
$countryType = 'country';
}

$formMapper
->with($this->trans('address.form.group_contact_label', array(), 'SonataCustomerBundle'), array(
'class' => 'col-md-7',
Expand All @@ -48,14 +59,14 @@ public function configureFormFields(FormMapper $formMapper)
->with($this->trans('address.form.group_advanced_label', array(), 'SonataCustomerBundle'), array(
'class' => 'col-md-5',
))
->add('type', 'sonata_customer_address_types', array('translation_domain' => 'SonataCustomerBundle'))
->add('type', $addressTypeType, array('translation_domain' => 'SonataCustomerBundle'))
->add('current', null, array('required' => false))
->add('name')
->end();

if (!$this->isChild()) {
$formMapper->with($this->trans('address.form.group_contact_label', array(), 'SonataCustomerBundle'))
->add('customer', 'sonata_type_model_list')
->add('customer', $modelListType)
->end()
;
}
Expand All @@ -69,7 +80,7 @@ public function configureFormFields(FormMapper $formMapper)
->add('address3')
->add('postcode')
->add('city')
->add('countryCode', 'country')
->add('countryCode', $countryType)
->end()
;
}
Expand All @@ -79,9 +90,16 @@ public function configureFormFields(FormMapper $formMapper)
*/
public function configureListFields(ListMapper $list)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$textType = 'Symfony\Component\Form\Extension\Core\Type\TextType';
} else {
$textType = 'text';
}

$list
->addIdentifier('name')
->add('fulladdress', 'string', array('code' => 'getFullAddressHtml', 'template' => 'SonataCustomerBundle:Admin:list_address.html.twig'))
->add('fulladdress', $textType, array('code' => 'getFullAddressHtml', 'template' => 'SonataCustomerBundle:Admin:list_address.html.twig'))
->add('current')
->add('typeCode', 'trans', array('catalogue' => $this->translationDomain))
;
Expand All @@ -92,9 +110,16 @@ public function configureListFields(ListMapper $list)
*/
protected function configureDatagridFilters(DatagridMapper $filter)
{
// NEXT_MAJOR: Keep FQCN when bumping Symfony requirement to 2.8+.
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$addressTypeType = 'Sonata\CustomerBundle\Form\Type\AddressTypeType';
} else {
$addressTypeType = 'sonata_customer_address_types';
}

$filter
->add('current')
->add('type', null, array(), 'sonata_customer_address_types', array('translation_domain' => 'SonataCustomerBundle'))
->add('type', null, array(), $addressTypeType, array('translation_domain' => 'SonataCustomerBundle'))
;

if (!$this->isChild()) {
Expand Down
Loading

0 comments on commit acd31fc

Please sign in to comment.