From 18926d496a839b8cea3c0f337b2e1d8fc12f5b71 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Wed, 2 Apr 2025 00:03:56 +0200
Subject: [PATCH 1/9] form add extra data
---
forms.rst | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/forms.rst b/forms.rst
index 38006169cdb..08ce24c1239 100644
--- a/forms.rst
+++ b/forms.rst
@@ -947,6 +947,59 @@ These "unmapped fields" can be set and accessed in a controller with::
Additionally, if there are any fields on the form that aren't included in
the submitted data, those fields will be explicitly set to ``null``.
+Extra fields
+~~~~~~~~~~~~~~~
+
+All form fields are considered properties of the object but you can inject fields
+directly into your view without specifying them in the form definition.
+They can be retrieved via the ``getExtraData`` :class:`Symfony\\Component\\Form\\FormTypeInterface`.
+
+This is a creation user form::
+
+ // ...
+ use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
+ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
+ use Symfony\Component\Form\FormBuilderInterface;
+ use App\User;
+
+ class UserCreateType extends AbstractType
+ {
+ public function buildForm(FormBuilderInterface $builder, array $options): void
+ {
+ $builder
+ ->add('username', TextType::class)
+ ->add('email', EmailType::class)
+ ;
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults([
+ 'data_class' => User::class,
+ ]);
+ }
+ }
+
+The extra fields can be injected like this::
+
+ {# templates/user/create.html.twig #}
+ {{ form_start(form) }}
+ {{ form_row(form.username) }}
+ {{ form_row(form.email) }}
+
+ {# Hidden field to send additional sponsorship code #}
+
+
+
+ {{ form_end(form) }}
+
+Here, the sponsorship code is an extra field injected at view level.
+
+You can get the referraCode via ``getExtraData``::
+
+ $extraData = $form->getExtraData();
+ $referraCode = $extraData['referralCode'] ?? null;
+
Learn more
----------
From b751d42ebe5f2db8ef338002beec5941d08ebae5 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Wed, 2 Apr 2025 15:28:13 +0200
Subject: [PATCH 2/9] Fix syntax
---
forms.rst | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/forms.rst b/forms.rst
index 08ce24c1239..c265d0c7faa 100644
--- a/forms.rst
+++ b/forms.rst
@@ -948,19 +948,18 @@ Additionally, if there are any fields on the form that aren't included in
the submitted data, those fields will be explicitly set to ``null``.
Extra fields
-~~~~~~~~~~~~~~~
+~~~~~~~~~~~~
-All form fields are considered properties of the object but you can inject fields
-directly into your view without specifying them in the form definition.
-They can be retrieved via the ``getExtraData`` :class:`Symfony\\Component\\Form\\FormTypeInterface`.
+All form fields are considered properties of the object but you can inject fields directly into your view without specifying them in the form definition.
+They can be retrieved via the ``getExtraData`` :class:`Symfony\\Component\\Form\\FormTypeInterface`.
This is a creation user form::
// ...
+ use App\User;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
- use App\User;
class UserCreateType extends AbstractType
{
@@ -980,7 +979,9 @@ This is a creation user form::
}
}
-The extra fields can be injected like this::
+The extra fields can be injected like this:
+
+.. code-block:: twig
{# templates/user/create.html.twig #}
{{ form_start(form) }}
@@ -995,7 +996,7 @@ The extra fields can be injected like this::
Here, the sponsorship code is an extra field injected at view level.
-You can get the referraCode via ``getExtraData``::
+You can get the referraCode via ``getExtraData``::
$extraData = $form->getExtraData();
$referraCode = $extraData['referralCode'] ?? null;
From 92dd2021e218cddceefd184c28e5123e65a72119 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Wed, 2 Apr 2025 15:29:53 +0200
Subject: [PATCH 3/9] Fix twig syntax
---
forms.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/forms.rst b/forms.rst
index c265d0c7faa..0ac6d213b08 100644
--- a/forms.rst
+++ b/forms.rst
@@ -981,7 +981,7 @@ This is a creation user form::
The extra fields can be injected like this:
-.. code-block:: twig
+.. code-block:: html+twig
{# templates/user/create.html.twig #}
{{ form_start(form) }}
@@ -989,7 +989,7 @@ The extra fields can be injected like this:
{{ form_row(form.email) }}
{# Hidden field to send additional sponsorship code #}
-
+
{{ form_end(form) }}
From ddfdc728c1b5050ae73ebb59ccb82f0915eadde2 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Wed, 2 Apr 2025 15:32:45 +0200
Subject: [PATCH 4/9] referraCode to referralCode
---
forms.rst | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/forms.rst b/forms.rst
index 0ac6d213b08..e8d5abc8dd4 100644
--- a/forms.rst
+++ b/forms.rst
@@ -988,18 +988,18 @@ The extra fields can be injected like this:
{{ form_row(form.username) }}
{{ form_row(form.email) }}
- {# Hidden field to send additional sponsorship code #}
+ {# Hidden field to send additional referral code #}
{{ form_end(form) }}
-Here, the sponsorship code is an extra field injected at view level.
+Here, the referral code is an extra field injected at view level.
-You can get the referraCode via ``getExtraData``::
+You can get the referral code via ``getExtraData``::
$extraData = $form->getExtraData();
- $referraCode = $extraData['referralCode'] ?? null;
+ $referralCode = $extraData['referralCode'] ?? null;
Learn more
----------
From 522e74cd37788f33b528029fd5bf0b33ba89d267 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Tue, 8 Apr 2025 12:18:53 +0200
Subject: [PATCH 5/9] Add user_create form name explanation
---
forms.rst | 3 +++
1 file changed, 3 insertions(+)
diff --git a/forms.rst b/forms.rst
index e8d5abc8dd4..bc651772300 100644
--- a/forms.rst
+++ b/forms.rst
@@ -996,6 +996,9 @@ The extra fields can be injected like this:
Here, the referral code is an extra field injected at view level.
+The field name is composed of form ``user_create`` and the field name ``referralCode``.
+It's automatically generated from the form class name. You can :ref:`override it `
+
You can get the referral code via ``getExtraData``::
$extraData = $form->getExtraData();
From 391f99bcdd201ac6078e19feeb83e0f0d382f4d8 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Tue, 8 Apr 2025 14:04:31 +0200
Subject: [PATCH 6/9] Remove trailing whitespace
---
forms.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/forms.rst b/forms.rst
index bc651772300..e94b4accddd 100644
--- a/forms.rst
+++ b/forms.rst
@@ -996,8 +996,8 @@ The extra fields can be injected like this:
Here, the referral code is an extra field injected at view level.
-The field name is composed of form ``user_create`` and the field name ``referralCode``.
-It's automatically generated from the form class name. You can :ref:`override it `
+The field name is composed of form ``user_create`` and the field name ``referralCode``.
+It's automatically generated from the form class name. You can :ref:`override it `
You can get the referral code via ``getExtraData``::
From 9ef444b5b2ba7ed1503ba1f902eb42b95ff8de29 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Mon, 14 Apr 2025 09:40:27 +0200
Subject: [PATCH 7/9] Add dynamic form name
---
forms.rst | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/forms.rst b/forms.rst
index e94b4accddd..4ed666e0041 100644
--- a/forms.rst
+++ b/forms.rst
@@ -950,7 +950,8 @@ the submitted data, those fields will be explicitly set to ``null``.
Extra fields
~~~~~~~~~~~~
-All form fields are considered properties of the object but you can inject fields directly into your view without specifying them in the form definition.
+All form fields are considered properties of the object but you can inject
+fields directly into your view without specifying them in the form definition.
They can be retrieved via the ``getExtraData`` :class:`Symfony\\Component\\Form\\FormTypeInterface`.
This is a creation user form::
@@ -999,6 +1000,14 @@ Here, the referral code is an extra field injected at view level.
The field name is composed of form ``user_create`` and the field name ``referralCode``.
It's automatically generated from the form class name. You can :ref:`override it `
+Or you can use use
+.. code-block:: html+twig
+ {{ form.vars.full_name ~ '[referralCode]' }}
+
+to render the form name dynamically
+
+{{ form.vars.full_name ~ '[description]' }}
+
You can get the referral code via ``getExtraData``::
$extraData = $form->getExtraData();
From 7774b210a778538a3c44d7af967a9a3b05e3efc8 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Mon, 14 Apr 2025 09:45:44 +0200
Subject: [PATCH 8/9] Fix syntax
---
forms.rst | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/forms.rst b/forms.rst
index 4ed666e0041..27169a33155 100644
--- a/forms.rst
+++ b/forms.rst
@@ -950,7 +950,7 @@ the submitted data, those fields will be explicitly set to ``null``.
Extra fields
~~~~~~~~~~~~
-All form fields are considered properties of the object but you can inject
+All form fields are considered properties of the object but you can inject
fields directly into your view without specifying them in the form definition.
They can be retrieved via the ``getExtraData`` :class:`Symfony\\Component\\Form\\FormTypeInterface`.
@@ -1000,14 +1000,14 @@ Here, the referral code is an extra field injected at view level.
The field name is composed of form ``user_create`` and the field name ``referralCode``.
It's automatically generated from the form class name. You can :ref:`override it `
-Or you can use use
-.. code-block:: html+twig
+Or you can use use
+
+.. code-block:: twig
+
{{ form.vars.full_name ~ '[referralCode]' }}
to render the form name dynamically
-{{ form.vars.full_name ~ '[description]' }}
-
You can get the referral code via ``getExtraData``::
$extraData = $form->getExtraData();
From c5388d4c1f0e10435c3ee87a664856d1dcaa59a2 Mon Sep 17 00:00:00 2001
From: Arkalo2 <24898676+Arkalo2@users.noreply.github.com>
Date: Mon, 14 Apr 2025 09:49:07 +0200
Subject: [PATCH 9/9] Fix syntax
---
forms.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/forms.rst b/forms.rst
index 27169a33155..0186423b139 100644
--- a/forms.rst
+++ b/forms.rst
@@ -1000,11 +1000,11 @@ Here, the referral code is an extra field injected at view level.
The field name is composed of form ``user_create`` and the field name ``referralCode``.
It's automatically generated from the form class name. You can :ref:`override it `
-Or you can use use
+Or you can use
.. code-block:: twig
- {{ form.vars.full_name ~ '[referralCode]' }}
+ {{ form.vars.full_name ~ '[referralCode]' }}
to render the form name dynamically