Crud - как настроить пользовательскую форму в поле коллекции для редактирования
Мне нужна помощь в настройке collectionField на crudController.
У меня есть 3 объекта: wheel (1,n) - (0,1) wheelsOffers (0,1) - (1,n) Offer. У WheelsOffers было немного собственности. Я хочу добавить collectionField в мою форму редактирования wheel crud для управления множеством предложений с помощью колеса с несколькими реляционными свойствами. Мне нужен пользовательский formType: wheelsOffersType.
В wheelCrudController:
public function configureFields(string $pageName): iterable
{
return [
TextField::new('name'),
TextEditorField::new('description'),
CollectionField::new('wheelsOffers', 'Offres')
->onlyOnForms()
->setFormType(WheelsOffersType::class)
];
}
В WheelsOffersType:
class WheelsOffersType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('offer', EntityType::class)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => WheelsOffers::class,
'csrf_protection' => false
]);
}
}
в Entity Wheel:
/**
* @ORM\OneToMany(targetEntity=WheelsOffers::class, mappedBy="wheel")
*/
private $wheelsOffers;
в объекте WheelsOffers:
/**
* @ORM\ManyToOne(targetEntity=Wheel::class, inversedBy="wheelsOffers")
*/
private $wheel;
/**
* @ORM\ManyToOne(targetEntity=Offer::class, inversedBy="wheelsOffers")
*/
private $offer;
в предложении сущности:
/**
* @ORM\OneToMany(targetEntity=WheelsOffers::class, mappedBy="offer")
*/
private $wheelsOffers;
Но на самом деле я заблокирован undefinedOptionsException, которого я не понимаю:
Произошла ошибка при разрешении параметров формы "App\Form\WheelsOffersType": параметры "allow_add", "allow_delete", "delete_empty", "entry_options" не существуют. Определенные параметры: "действие", "allow_extra_fields", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "complex", "constraints", "csrf_field_name". "," csrf_message "," csrf_protection "," csrf_token_id "," csrf_token_manager "," data "," data_class "," disabled "," documentation "," ea_crud_form "," empty_data "," error_bubbling ","error_mapping "," extra_fields_message "," help "," help_attr "," help_html "," help_translation_parameters "," inherit_data "," invalid_message "," invalid_message_parameters "," is_empty_callback "," label "," label_attrat ", "label_html", "label_translation_parameters", "mapped", "method", "post_max_size_message", "property_path", "required", "row_attr", "translation_domain", "trim", "upload_max_size_message", "validation_groups".inherit_data "," invalid_message "," invalid_message_parameters "," is_empty_callback "," label "," label_attr "," label_format "," label_html "," label_translation_parameters "," mapped "," method "," post_max_size_message ", "обязательный", "row_attr", "translation_domain", "trim", "upload_max_size_message", "validation_groups".inherit_data "," invalid_message "," invalid_message_parameters "," is_empty_callback "," label "," label_attr "," label_format "," label_html "," label_translation_parameters "," mapped "," method "," post_max_size_message ", "обязательный", "row_attr", "translation_domain", "trim", "upload_max_size_message", "validation_groups"."required", "row_attr", "translation_domain", "trim", "upload_max_size_message", "validation_groups"."обязательный", "row_attr", "translation_domain", "trim", "upload_max_size_message", "validation_groups".
Я пробовал использовать:
1.
CollectionFIeld->setEntryType(WheelsOffers::class),
вместо setFormType, но я думаю, что это неправильный путь
- Я установил setFormTypeOptions
->setFormType(WheelsOffersType::class)
->setFormTypeOptions([
'allow_add'=>false,
'allow_delete'=>false,
'delete_empty'=>false,
'entry_options'=>false
]),
тот же результат, указанный ранее?
3.
CollectionFIeld->setEntryType(WheelsOffersType::class),
вместо setFormType, но я тоже думаю, что это неправильный путь
Как я могу настроить свой collectionField?
1 ответ
Ответ: в CrudController
public function configureFields(string $pageName): iterable
{
return [
TextField::new('name'),
...
CollectionField::new('wheelsOffers', 'Offres')
->onlyOnForms()
->setEntryType(WheelsOffersType::class),
];
}
в WheelOfferType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('offer', EntityType::class, ['class'=>Offer::class])
->add('stock', IntegerType::class)
...
;
}
в колесе сущностей и предлагают:
/**
* @ORM\OneToMany(targetEntity=WheelsOffers::class, mappedBy="wheel", cascade={"persist"}, orphanRemoval=true)
*/
private $wheelsOffers;
спасибо всем, кто удосужился посмотреть.