如何在符号中构建嵌套形式
我正在使用EasyAdmin为实体创建控制器( process ),该控制器与另一个实体有关( e节)(一对多关系)与另一个实体有关系(子段)(也是一对一的)。
在“新”过程的“新”形式中,我有一个字段,该字段是easyAdmin集合以添加部分的字段,但是由于这些部分具有小节,我需要在该小节的各节中添加另一个平等字段...具有与相同的行为小节。 easyAdmin类型的字段(单击“添加项目”时,为其他实体显示了一个迷你表单)。
主要形式是为了创建一个过程,“部分”字段是为了向该过程添加部分,并且在部分中,我需要一个像EasyAdmin中的一个按钮来为该部分创建更多子部分。
这是过程的主要形式:
,这就是收集类型字段的样子,用于创建各节的字段:
这是过程控制器:一个称为“ secciontype ”的自定义字段)
namespace App\Controller\Admin;
use App\Entity\Proceso;
use App\Form\Type\SeccionType;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
class ProcesoCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Proceso::class;
}
public function configureFields(string $pageName): iterable
{
yield TextField::new('nombre');
yield TextEditorField::new('descripcion');
yield CollectionField::new('secciones') // <--- This is Sections field with the custom Symfony formType
->setEntryType(SeccionType::class)
->setFormTypeOptions(['block_prefix' => 'secciones_form',])
->addCssClass('actividadesFld');
yield BooleanField::new('estado')->renderAsSwitch(false);
}
}
,这是自定义字段的类 scciontype
namespace App\Form\Type;
use App\Entity\Seccion;
use App\Entity\Proceso;
use App\Entity\Subseccion;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormTypeInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use Symfony\Component\Validator\Constraints\NotNull;
class SeccionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('description')
->add('order')
->add('tag')
// ->add('proccess')
->add('subSection', CollectionType::class, ['entry_type' => ..?]);
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Seccion::class,
]);
}
}
任何帮助或建议,我都会非常感谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您没有添加 =&gt;您在secciontype.php中的collectionType以及 =&gt;真的。您还应该创建一个subsecciontype,以在选项。那应该是一个很好的开始。
it seems you did not add the allow-add => true option to your CollectionType in SeccionType.php, as well as prototype => true. You should also probably create a SubSeccionType to give in the entry-type option. That should be a good start to move along.