class User
{
/**
* @var Phone
*/
protected $phone;
}
class Phone
{
/**
* @var Code
*/
protected $code;
}
class Code
{
/**
* @var string
*/
protected $code;
}
class UserEdit extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phone', PhoneEdit::class);
}
}
class PhoneEdit extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('code', CodeEdit::class);
}
}
class CodeEdit extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$notBlank = new NotBlank();
$builder->add('code', TextType::class, array('constraints' => $notBlank));
}
}
class UserEdit extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options){
$notBlank = new NotBlank();
$builder
->add('lastName' , TextType::class, array('constraints' => $notBlank))
->add('firstName' , TextType::class, array('constraints' => $notBlank))
->add('secondName', TextType::class, array('constraints' => $notBlank))
->add('extendedInfo',UserExtendedInfoEdit::class)
;
}
}
class UserExtendedInfoEdit extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$notBlank = new NotBlank();
$builder
->add('phone' , TextType::class, array('constraints' => $notBlank))
;
}
}
Ниже @teen предложил варианты обхода этого.