Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] [Form collections] Add informations about the form events#19443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Sarah-eit wants to merge1 commit intosymfony:5.4
base:5.4
Choose a base branch
Loading
fromSarah-eit:add_informations_about_form_events
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletionsform/form_collections.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -125,6 +125,48 @@ inside the task form itself::
}
}

.. note::

If you want to access the linked data, you will need to use events::

// src/Form/TagType.php

// ...
public function buildForm(FormBuilderInterface $builder, array $options): void
{
// ...
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
$data = $event->getData();
// ...
});
}
// ...

And when the form (which call the CollectionType) sets the ``by_reference`` option
to false, the entire form must to be inside a ``PRE_SET_DATA`` event::

// src/Form/TaskType.php

// ...
public function buildForm(FormBuilderInterface $builder, array $options): void
{
// ...
$builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) {
$form = $event->getForm();
$form->add('tags', CollectionType::class, [
'entry_type' => TagType::class,
'by_reference' => false,
]);
});
// ...
}
// ...

.. seealso::

If you want to learn more about the form events, read :ref:`events`
and :ref:`dynamic_form_modification`.

In your controller, you'll create a new form from the ``TaskType``::

// src/Controller/TaskController.php
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp