ソースを参照

Inscription/connexion utilisateur (nouveaux champs, connexion via email)

reduction
Guillaume 4年前
コミット
8a6e3dcd37
2個のファイルの変更101行の追加0行の削除
  1. +44
    -0
      ShopBundle/Form/RegistrationType.php
  2. +57
    -0
      ShopBundle/Model/User.php

+ 44
- 0
ShopBundle/Form/RegistrationType.php ファイルの表示

@@ -0,0 +1,44 @@
<?php

namespace Lc\ShopBundle\Form;

use FOS\UserBundle\Form\Type\RegistrationFormType as BaseRegistrationFormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
public function getParent()
{
return BaseRegistrationFormType::class;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->remove('username')
->add('gender', ChoiceType::class, [
'label' => 'Titre',
'multiple' => false,
'expanded' => true,
'choices' => [
'Madame' => 1,
'Monsieur' => 0,
]
])
->add('firstName', TextType::class, [
'label' => 'Prénom'
])
->add('lastName', TextType::class, [
'label' => 'Nom'
])
->add('isSubscribedNewsletter', CheckboxType::class, [
'label' => 'S\'inscrire à la newsletter',
'required' => false
]);
}


}

+ 57
- 0
ShopBundle/Model/User.php ファイルの表示

@@ -54,6 +54,21 @@ abstract class User extends UserModelFOS
*/
protected $isSubscribedNewsletter;

/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
protected $firstname;

/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
protected $lastname;

/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $gender;

public function __construct()
{
parent::__construct();
@@ -63,6 +78,12 @@ abstract class User extends UserModelFOS
$this->carts = new ArrayCollection();
}

public function setEmail($email)
{
$this->setUsername($email);
return parent::setEmail($email);
}

public function getPhone(): ?string
{
return $this->phone;
@@ -234,4 +255,40 @@ abstract class User extends UserModelFOS

return $this;
}

public function getFirstname(): ?string
{
return $this->firstname;
}

public function setFirstname(?string $firstname): self
{
$this->firstname = $firstname;

return $this;
}

public function getLastname(): ?string
{
return $this->lastname;
}

public function setLastname(?string $lastname): self
{
$this->lastname = $lastname;

return $this;
}

public function getGender(): ?bool
{
return $this->gender;
}

public function setGender(?bool $gender): self
{
$this->gender = $gender;

return $this;
}
}

読み込み中…
キャンセル
保存