Skip to content

Commit 1fd4179

Browse files
committed
Merge pull request symfony#1910 from richardmiller/changing_we_cookbook_form
Changed uses of we in form cookbooks
2 parents 2a26b52 + abc56fe commit 1fd4179

File tree

5 files changed

+91
-91
lines changed

5 files changed

+91
-91
lines changed

cookbook/form/create_custom_field_type.rst

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ How to Create a Custom Form Field Type
55
======================================
66

77
Symfony comes with a bunch of core field types available for building forms.
8-
However there are situations where we want to create a custom form field
9-
type for a specific purpose. This recipe assumes we need a field definition
8+
However there are situations where you may want to create a custom form field
9+
type for a specific purpose. This recipe assumes you need a field definition
1010
that holds a person's gender, based on the existing choice field. This section
11-
explains how the field is defined, how we can customize its layout and finally,
12-
how we can register it for use in our application.
11+
explains how the field is defined, how you can customize its layout and finally,
12+
how you can register it for use in your application.
1313

1414
Defining the Field Type
1515
-----------------------
1616

17-
In order to create the custom field type, first we have to create the class
18-
representing the field. In our situation the class holding the field type
17+
In order to create the custom field type, first you have to create the class
18+
representing the field. In this situation the class holding the field type
1919
will be called `GenderType` and the file will be stored in the default location
2020
for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extends
2121
:class:`Symfony\\Component\\Form\\AbstractType`::
@@ -54,8 +54,8 @@ for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extend
5454
The location of this file is not important - the ``Form\Type`` directory
5555
is just a convention.
5656

57-
Here, the return value of the ``getParent`` function indicates that we're
58-
extending the ``choice`` field type. This means that, by default, we inherit
57+
Here, the return value of the ``getParent`` function indicates that you're
58+
extending the ``choice`` field type. This means that, by default, you inherit
5959
all of the logic and rendering of that field type. To see some of the logic,
6060
check out the `ChoiceType`_ class. There are three methods that are particularly
6161
important:
@@ -86,7 +86,7 @@ The ``getName()`` method returns an identifier which should be unique in
8686
your application. This is used in various places, such as when customizing
8787
how your form type will be rendered.
8888

89-
The goal of our field was to extend the choice type to enable selection of
89+
The goal of this field was to extend the choice type to enable selection of
9090
a gender. This is achieved by fixing the ``choices`` to a list of possible
9191
genders.
9292

@@ -97,11 +97,11 @@ Each field type is rendered by a template fragment, which is determined in
9797
part by the value of your ``getName()`` method. For more information, see
9898
:ref:`cookbook-form-customization-form-themes`.
9999

100-
In this case, since our parent field is ``choice``, we don't *need* to do
101-
any work as our custom field type will automatically be rendered like a ``choice``
102-
type. But for the sake of this example, let's suppose that when our field
100+
In this case, since tge parent field is ``choice``, you don't *need* to do
101+
any work as the custom field type will automatically be rendered like a ``choice``
102+
type. But for the sake of this example, let's suppose that when your field
103103
is "expanded" (i.e. radio buttons or checkboxes, instead of a select field),
104-
we want to always render it in a ``ul`` element. In your form theme template
104+
you want to always render it in a ``ul`` element. In your form theme template
105105
(see above link for details), create a ``gender_widget`` block to handle this:
106106

107107
.. code-block:: html+jinja
@@ -172,12 +172,12 @@ Creating your Field Type as a Service
172172
So far, this entry has assumed that you have a very simple custom field type.
173173
But if you need access to configuration, a database connection, or some other
174174
service, then you'll want to register your custom type as a service. For
175-
example, suppose that we're storing the gender parameters in configuration:
175+
example, suppose that you're storing the gender parameters in configuration:
176176

177177
.. configuration-block::
178178

179179
.. code-block:: yaml
180-
180+
181181
# app/config/config.yml
182182
parameters:
183183
genders:
@@ -194,7 +194,7 @@ example, suppose that we're storing the gender parameters in configuration:
194194
</parameter>
195195
</parameters>
196196
197-
To use the parameter, we'll define our custom field type as a service, injecting
197+
To use the parameter, define your custom field type as a service, injecting
198198
the ``genders`` parameter value as the first argument to its to-be-created
199199
``__construct`` function:
200200

@@ -225,8 +225,8 @@ the ``genders`` parameter value as the first argument to its to-be-created
225225
for details.
226226

227227
Be sure that the ``alias`` attribute of the tag corresponds with the value
228-
returned by the ``getName`` method defined earlier. We'll see the importance
229-
of this in a moment when we use the custom field type. But first, add a ``__construct``
228+
returned by the ``getName`` method defined earlier. You'll see the importance
229+
of this in a moment when you use the custom field type. But first, add a ``__construct``
230230
argument to ``GenderType``, which receives the gender configuration::
231231

232232
// src/Acme/DemoBundle/Form/Type/GenderType.php
@@ -236,24 +236,24 @@ argument to ``GenderType``, which receives the gender configuration::
236236
class GenderType extends AbstractType
237237
{
238238
private $genderChoices;
239-
239+
240240
public function __construct(array $genderChoices)
241241
{
242242
$this->genderChoices = $genderChoices;
243243
}
244-
244+
245245
public function getDefaultOptions(array $options)
246246
{
247247
return array(
248248
'choices' => $this->genderChoices,
249249
);
250250
}
251-
251+
252252
// ...
253253
}
254254

255255
Great! The ``GenderType`` is now fueled by the configuration parameters and
256-
registered as a service. And because we used the ``form.type`` alias in its
256+
registered as a service. Additionally because you used the ``form.type`` alias in its
257257
configuration, using the field is now much easier::
258258

259259
// src/Acme/DemoBundle/Form/Type/AuthorType.php
@@ -270,8 +270,8 @@ configuration, using the field is now much easier::
270270
}
271271
}
272272

273-
Notice that instead of instantiating a new instance, we can just refer to
274-
it by the alias used in our service configuration, ``gender``. Have fun!
273+
Notice that instead of instantiating a new instance, you can just refer to
274+
it by the alias used in your service configuration, ``gender``. Have fun!
275275

276276
.. _`ChoiceType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
277277
.. _`FieldType`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php

cookbook/form/data_transformers.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ issue field in some form.
117117
$entityManager = $options['em'];
118118
$transformer = new IssueToNumberTransformer($entityManager);
119119

120-
// add a normal text field, but add our transformer to it
120+
// add a normal text field, but add your transformer to it
121121
$builder->add(
122122
$builder->create('issue', 'text')
123123
->prependNormTransformer($transformer)
@@ -164,11 +164,11 @@ types of underlying data.
164164
In any form, the 3 different types of data are:
165165

166166
1) **App data** - This is the data in the format used in your application
167-
(e.g. an ``Issue`` object). If you call ``Form::getData`` or ``Form::setData``,
167+
(e.g. an ``Issue`` object). If you call ``Form::getData`` or ``Form::setData``,
168168
you're dealing with the "app" data.
169169

170170
2) **Norm Data** - This is a normalized version of your data, and is commonly
171-
the same as your "app" data (though not in our example). It's not commonly
171+
the same as your "app" data (though not in this example). It's not commonly
172172
used directly.
173173

174174
3) **Client Data** - This is the format that's used to fill in the form fields
@@ -190,11 +190,11 @@ Which transformer you need depends on your situation.
190190

191191
To use the client transformer, call ``appendClientTransformer``.
192192

193-
So why did we use the norm transformer?
194-
---------------------------------------
193+
So why use the norm transformer?
194+
--------------------------------
195195

196-
In our example, the field is a ``text`` field, and we always expect a text
197-
field to be a simple, scalar format in the "norm" and "client" formats. For
196+
In this example, the field is a ``text`` field, and a text field is always
197+
expected to be a simple, scalar format in the "norm" and "client" formats. For
198198
this reason, the most appropriate transformer was the "norm" transformer
199199
(which converts to/from the *norm* format - string issue number - to the *app*
200200
format - Issue object).

cookbook/form/dynamic_form_generation.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ flexibility to your forms.
4949
Adding An Event Subscriber To A Form Class
5050
------------------------------------------
5151

52-
So, instead of directly adding that "name" widget via our ProductType form
52+
So, instead of directly adding that "name" widget via your ProductType form
5353
class, let's delegate the responsibility of creating that particular field
5454
to an Event Subscriber::
5555

@@ -76,7 +76,7 @@ to an Event Subscriber::
7676
}
7777

7878
The event subscriber is passed the FormFactory object in its constructor so
79-
that our new subscriber is capable of creating the form widget once it is
79+
that your new subscriber is capable of creating the form widget once it is
8080
notified of the dispatched event during form creation.
8181

8282
.. _`cookbook-forms-inside-subscriber-class`:
@@ -107,7 +107,7 @@ might look like the following::
107107

108108
public static function getSubscribedEvents()
109109
{
110-
// Tells the dispatcher that we want to listen on the form.pre_set_data
110+
// Tells the dispatcher that you want to listen on the form.pre_set_data
111111
// event and that the preSetData method should be called.
112112
return array(FormEvents::PRE_SET_DATA => 'preSetData');
113113
}
@@ -118,7 +118,7 @@ might look like the following::
118118
$form = $event->getForm();
119119

120120
// During form creation setData() is called with null as an argument
121-
// by the FormBuilder constructor. We're only concerned with when
121+
// by the FormBuilder constructor. You're only concerned with when
122122
// setData is called with an actual Entity object in it (whether new
123123
// or fetched with Doctrine). This if statement lets us skip right
124124
// over the null condition.
@@ -146,7 +146,7 @@ The `FormEvents class`_ serves an organizational purpose. It is a centralized lo
146146
in which you can find all of the various form events available.
147147

148148
While this example could have used the ``form.set_data`` event or even the ``form.post_set_data``
149-
events just as effectively, by using ``form.pre_set_data`` we guarantee that
149+
events just as effectively, by using ``form.pre_set_data`` you guarantee that
150150
the data being retrieved from the ``Event`` object has in no way been modified
151151
by any other subscribers or listeners. This is because ``form.pre_set_data``
152152
passes a `DataEvent`_ object instead of the `FilterDataEvent`_ object passed

0 commit comments

Comments
 (0)