Skip to content

Commit 17eef6a

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: cookbook/form/index.rst cookbook/map.rst.inc reference/forms/types/options/date_widget.rst.inc
2 parents cd9eda4 + 87c0536 commit 17eef6a

File tree

10 files changed

+143
-6
lines changed

10 files changed

+143
-6
lines changed

components/console/introduction.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,39 @@ You can also set these colors and options inside the tagname::
160160
// bold text on a yellow background
161161
$output->writeln('<bg=yellow;options=bold>foo</bg=yellow;options=bold>');
162162

163+
Verbosity Levels
164+
~~~~~~~~~~~~~~~~
165+
166+
The console has 3 levels of verbosity. These are defined in the
167+
:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:
168+
169+
================================== ===============================
170+
Option Value
171+
================================== ===============================
172+
OutputInterface::VERBOSITY_QUIET Do not output any messages
173+
OutputInterface::VERBOSITY_NORMAL The default verbosity level
174+
OutputInterface::VERBOSITY_VERBOSE Increased verbosity of messages
175+
================================== ===============================
176+
177+
You can specify the quiet verbosity level with the ``--quiet`` or ``-q``
178+
option. The ``--verbose`` or ``-v`` option is used when you want an increased
179+
level of verbosity.
180+
181+
.. tip::
182+
183+
The full exception stacktrace is printed if the ``VERBOSITY_VERBOSE``
184+
level is used.
185+
186+
It is possible to print a message in a command for only a specific verbosity
187+
level. For example::
188+
189+
if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) {
190+
$output->writeln(...);
191+
}
192+
193+
When the quiet level is used, all output is suppressed as the default
194+
:method:`Symfony\Component\Console\Output::write<Symfony\\Component\\Console\\Output::write>`
195+
method returns without actually printing.
163196

164197
Using Command Arguments
165198
-----------------------

components/dom_crawler.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,16 @@ To work with multi-dimensional fields::
278278
<input name="multi[dimensional]" />
279279
</form>
280280

281-
You must specify the fully qualified name of the field::
281+
Pass an array of values::
282282

283283
// Set a single field
284-
$form->setValue('multi[0]', 'value');
284+
$form->setValues(array('multi' => array('value')));
285285

286286
// Set multiple fields at once
287-
$form->setValue('multi', array(
287+
$form->setValues(array('multi' => array(
288288
1 => 'value',
289289
'dimensional' => 'an other value'
290-
));
290+
)));
291291

292292
This is great, but it gets better! The ``Form`` object allows you to interact
293293
with your form like a browser, selecting radio values, ticking checkboxes,

components/serializer.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ use the Serializer service created before::
9090
$person->setName('foo');
9191
$person->setAge(99);
9292

93-
$serializer->serialize($person, 'json'); // Output: {"name":"foo","age":99}
93+
$jsonContent = $serializer->serialize($person, 'json');
94+
95+
// $jsonContent contains {"name":"foo","age":99}
96+
97+
echo $jsonContent; // or return it in a Response
9498

9599
The first parameter of the :method:`Symfony\\Component\\Serializer\\Serializer::serialize`
96100
is the object to be serialized and the second is used to choose the proper encoder,

cookbook/form/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Form
1212
create_form_type_extension
1313
use_virtuals_forms
1414
unit_testing
15+
use_empty_data

cookbook/form/use_empty_data.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.. index::
2+
single: Form; Empty data
3+
4+
How to configure Empty Data for a Form Class
5+
============================================
6+
7+
The ``empty_data`` option allows you to specify an empty data set for your
8+
form class. This empty data set would be used if you bind your form, but
9+
haven't called ``setData()`` on your form or passed in data when you created
10+
you form. For example::
11+
12+
public function indexAction()
13+
{
14+
$blog = // ...
15+
16+
// $blog is passed in as the data, so the empty_data option is not needed
17+
$form = $this->createForm(new BlogType(), $blog);
18+
19+
// no data is passed in, so empty_data is used to get the "starting data"
20+
$form = $this->createForm(new BlogType());
21+
}
22+
23+
By default, ``empty_data`` is set to ``null``. Or, if you have specified
24+
a ``data_class`` option for your form class, it will default to a new instance
25+
of that class. That instance will be created by calling the constructor
26+
with no arguments.
27+
28+
If you want to override this default behavior, there are two ways to do this.
29+
30+
Option 1: Instantiate a new Class
31+
---------------------------------
32+
33+
One reason you might use this option is if you want to use a constructor
34+
that takes arguments. Remember, the default ``data_class`` option calls
35+
that constructor with no arguments::
36+
37+
// src/Acme/DemoBundle/Form/Type/BlogType.php
38+
// ...
39+
40+
use Symfony\Component\Form\AbstractType;
41+
use Acme\DemoBundle\Entity\Blog;
42+
43+
class BlogType extends AbstractType
44+
{
45+
private $someDependency;
46+
47+
public function __construct($someDependency)
48+
{
49+
$this->someDependency = $someDependency;
50+
}
51+
// ...
52+
53+
public function getDefaultOptions()
54+
{
55+
return array(
56+
'empty_data' => new Blog($this->someDependency),
57+
);
58+
}
59+
}
60+
61+
You can instantiate your class however you want. In this example, we pass
62+
some dependency into the ``BlogType`` when we instantiate it, then use that
63+
to instantiate the ``Blog`` object. The point is, you can set ``empty_data``
64+
to the exact "new" object that you want to use.
65+
66+
Option 2: Provide a Closure
67+
---------------------------
68+
69+
Using a closure is the preferred method, since it will only create the object
70+
if it is needed.
71+
72+
The closure must accept a ``FormInterface`` instance as the first argument::
73+
74+
use Symfony\Component\Form\FormInterface;
75+
// ...
76+
77+
public function getDefaultOptions()
78+
{
79+
return array(
80+
'empty_data' => function (FormInterface $form) {
81+
return new Blog($form->get('title')->getData());
82+
},
83+
);
84+
}

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
* :doc:`/cookbook/form/create_form_type_extension`
8484
* :doc:`/cookbook/form/use_virtuals_forms`
8585
* :doc:`/cookbook/form/unit_testing`
86+
* :doc:`/cookbook/form/use_empty_data`
8687
* (validation) :doc:`/cookbook/validation/custom_constraint`
8788
* (doctrine) :doc:`/cookbook/doctrine/file_uploads`
8889

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. caution::
2+
3+
If ``timestamp`` is used, ``DateType`` is limited to dates between
4+
Fri, 13 Dec 1901 20:45:54 GMT and Tue, 19 Jan 2038 03:14:07 GMT on 32bit
5+
systems. This is due to a `limitation in PHP itself <http://php.net/manual/en/function.date.php#refsect1-function.date-changelog>`_.

reference/forms/types/options/date_input.rst.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ your underlying object. Valid values are:
1212
* ``timestamp`` (e.g. ``1307232000``)
1313

1414
The value that comes back from the form will also be normalized back into
15-
this format.
15+
this format.
16+
17+
.. include:: /reference/forms/types/options/_date_limitation.rst.inc

reference/forms/types/options/date_widget.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ The basic way in which this field should be rendered. Can be one of the followin
1212

1313
* ``single_text``: renders a single input of type date (text in Symfony 2.0). User's
1414
input is validated based on the `format`_ option.
15+
16+
.. include:: /reference/forms/types/options/_date_limitation.rst.inc

reference/forms/types/options/empty_data.rst.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ value is selected, you can do it like this:
2020
'empty_value' => 'Choose your gender',
2121
'empty_data' => null
2222
));
23+
24+
.. note::
25+
26+
If you want to set the ``empty_data`` option for your entire form class,
27+
see the cookbook article :doc:`/cookbook/form/use_empty_data`

0 commit comments

Comments
 (0)