Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms Refactoring #399

Closed
wants to merge 281 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
281 commits
Select commit Hold shift + click to select a range
e3e8c29
Merge branch 'bugfix' into experimental
Feb 24, 2011
acc5c76
[Form] Fixed failing DateFieldTest and TimeFieldTest
Feb 24, 2011
0f8a413
[Form] Fixed EntityChoiceFieldTest
Feb 24, 2011
87b4178
[Form] Fixed DateTimeFieldTest
Feb 24, 2011
848ec01
[Form] Refactored RepeatedField to FormFactory
Feb 24, 2011
f2c1976
[Form] Refactored FileField to FormFactory and fixed file upload mech…
Feb 24, 2011
e334c47
[Form] Registered FormFactory in the DIC
Feb 24, 2011
eca2b87
Merge branch 'master' into experimental
Feb 24, 2011
c6e9fd9
[Form] Fixed various bugs
Feb 24, 2011
adbf2cb
[Form] Added ArrayAccess interface to DefaultRenderer
Feb 25, 2011
02d2121
[Form] Improved rendering
Feb 28, 2011
c1edf11
[Form] Removed notion of "hidden" fields
Feb 28, 2011
528ef55
[Form] Implemented generic data filter hooks
Mar 1, 2011
9eff64d
[Form] Added EventListener implementation and moved CollectionField t…
Mar 1, 2011
8a6246b
[Form] Refactored contents of FormFactory into individual FieldConfig…
Mar 2, 2011
68013f4
Merge remote branch 'symfony/master' into experimental
Mar 2, 2011
5705f74
[Form] Refactored FieldFactory and moved new implementation into the …
Mar 2, 2011
ea49621
[Form] Fixed CSRF protection
Mar 2, 2011
e53c688
[Form] Fixed RepeatedField, improved structure of the Twig templates
Mar 2, 2011
0f8cd43
[Form] The TwigTheme now accepts several templates
Mar 2, 2011
bfbc112
[Form] Added ArrayAccess to DefaultRenderer
Mar 2, 2011
4346097
[Form] Added TODOs and a tweak
Mar 4, 2011
0bf5663
Merge branch 'event-manager' into experimental
Mar 13, 2011
f64f550
Merge remote branch 'symfony/master' into experimental
Mar 16, 2011
fb8efab
[Form] Fixed a couple of failing tests
Mar 16, 2011
e85aab2
[Form] Changed form to use the new EventDispatcher implementation
Mar 16, 2011
caa49aa
[Form] Moved trimming logic to listener
Mar 17, 2011
cb283d3
[Form] Renamed 'key' to 'name'. Removed setKey() totally.
Mar 17, 2011
eba602e
[Form] Removed dependency from renderer plugins on fields. The field …
Mar 17, 2011
1c9a007
Merge branch 'event-manager' into experimental
Mar 17, 2011
f0d841e
[Form] Fixed DateTimeToArrayTransformer when transforming empty value…
Mar 17, 2011
50ce0d5
[Form] Removed FieldInterface::getDisplayedData(). Use getTransformed…
Mar 17, 2011
ffa5bd2
[Form] Moved logic of Field::isMultipart() to rendering layer
Mar 17, 2011
f2f7889
[Form] Removed deprecated method preprocessData()
Mar 17, 2011
5bfd02b
[Form] Renamed bind() to bindRequest(). It is now semantically the sa…
Mar 17, 2011
7a63b84
[Form] Renamed submit() to bind()
Mar 17, 2011
8e41cc6
[Form] Moved form logic to event listeners
Mar 17, 2011
d00f1fa
[Form] Removed unused method Form::deepArrayUnion()
Mar 17, 2011
85b61fe
First attempt of PhpTheme.
beberlei Mar 17, 2011
3bc825b
Merge branch 'experimental' of git://github.com/bschussek/symfony int…
beberlei Mar 17, 2011
0799662
[Form] Extracted data mapping logic from Form into ObjectMapperListener
Mar 17, 2011
a51321c
[Form] Moved validation logic to ValidationListener
Mar 17, 2011
76b0041
[Form] Implemented first PhpTheme attempt
beberlei Mar 17, 2011
d5adaa2
[FrameworkBundle] Fixed filename of TraceableEventDispatcher
johnwards Mar 17, 2011
380afc5
[FrameworkBundle] Added missing argument for listenerToString() call
johnwards Mar 17, 2011
cd3e184
[FrameworkBundle] Fixed typo in ProfileListener
johnwards Mar 17, 2011
c56a803
[FrameworkBundle] Fixed undefined $response variable in ProfilerListener
johnwards Mar 17, 2011
694c7fd
[FrameworKBundle] Fixed TraceableEventDispatcher to use parent::getLi…
johnwards Mar 17, 2011
7c0fe6a
[FrameworkBundle] Fixed order of the classes to compile for EventDisp…
johnwards Mar 17, 2011
52f382a
Merge branch 'event-manager' into experimental
Mar 18, 2011
3f70f89
Merge remote branch 'symfony/master' into experimental
Mar 18, 2011
9caaf0f
[Form] Introduced FieldBuilder for field/form creation and made Field…
Mar 18, 2011
4cb76c0
[Form] Moved error distribution logic to validation listener
Mar 18, 2011
700c96e
[Form] Moved FieldFactoryTest to FormFactoryTest and fixed it
Mar 18, 2011
97d0183
[Form] Moved properties propertyPath, modifyByReference, validationGr…
Mar 18, 2011
f86ecec
[Form] Extracted data validation logic into DataValidatorInterface
Mar 18, 2011
0b929ee
[Form] Renamed ValueTransformers to DataTransformers to fit with Data…
Mar 18, 2011
2a1e394
[Form] Renamed field configs to types. Everywhere else, we are referr…
Mar 18, 2011
1c85daa
[Form] Split FieldBuilder into FieldBuilder and FormBuilder to make c…
Mar 18, 2011
6bc79a1
[Form] Renamed different kinds of data transformers within a field fo…
Mar 18, 2011
b66b832
[Form] Fixed undefined variable in DefaultRenderer
Mar 18, 2011
d44e226
Merge branch 'experimental' of git://github.com/bschussek/symfony int…
beberlei Mar 19, 2011
bb8c2a9
Rename this to renderer to be able to use it in Php Templating
beberlei Mar 19, 2011
89215d1
Merge remote branch 'symfony/master' into experimental
Mar 19, 2011
8742caf
[FrameworkBundle] Fixed DI configuration for field types
Mar 19, 2011
3e2b8e5
Fix some missing use statements and small bugs.
beberlei Mar 19, 2011
3e17b26
[Form] Moved CSRF protection into separate field
Mar 19, 2011
d2210a2
[Form] Removed unused Form::isCsrfTokenValid()
Mar 19, 2011
44e85ae
Finished first version of PhpTheme, added huge functional test.
beberlei Mar 19, 2011
32e1a7c
Merge bschussek/experimental into branch forms.
beberlei Mar 19, 2011
af60ddf
Moved PhpTheme to FrameworkBundle and renamed to PhpEngineTheme
beberlei Mar 19, 2011
7f92841
[Form] Moved namespace FieldGuesser to Type\Guesser
Mar 19, 2011
0259d4d
[Form] Moved namespace DataValidator to Validator
Mar 19, 2011
43a24fa
[Form] Renamed events to match terminology in Field
Mar 19, 2011
39c2d3f
[Form] Add PhpTheme that relies on no Template Engine, generalize tes…
beberlei Mar 19, 2011
c05b3c4
[Form] Add DefaultFormFactory for convenience usage outside of a DIC …
beberlei Mar 19, 2011
65353bd
[Form] Fixed failing choice field tests
Mar 19, 2011
3586268
[Form] Renamed field types. They are now always the name of the type …
Mar 19, 2011
c4b7a77
Merge remote branch 'beberlei/forms' into beberlei-merge
Mar 19, 2011
6793bcd
[Form] Removed magic from method signature of add()
Mar 19, 2011
fb2db58
[Form] Added fluid interface for inline adding of sub-builders to a b…
Mar 19, 2011
e9cb197
[Form] Optimized code in Form to remove one event listener
Mar 19, 2011
a1c3d21
[Form] Added comment
Mar 19, 2011
864a3ec
[Form] Add StripTagsFilter EventListener
beberlei Mar 19, 2011
d622136
Merge branch 'experimental' of git://github.com/bschussek/symfony int…
beberlei Mar 19, 2011
b43318e
[Form] Add tests for untested classes.
beberlei Mar 19, 2011
2c6c89d
Merge remote branch 'beberlei/forms' into beberlei-merge
Mar 20, 2011
295d017
[Form] Renamed StripTagsFilter to StripTagsListener until we have bet…
Mar 20, 2011
b5656f1
[Form] Renamed ObjectMapper to PropertyPathMapper
Mar 20, 2011
cb599f4
[Form] Renamed field option 'disabled' to 'read_only'. How to render …
Mar 20, 2011
fc7281b
[Form] Extracted validation logic of form. Fields can now contain mul…
Mar 20, 2011
2dbb417
[Form] Merged Field and Form. Merged FieldBuilder and FormBuilder. Af…
Mar 20, 2011
119866e
[Form] Renamed FormBuilder::getInstance() to getForm()
Mar 20, 2011
6c9ff0a
[Form] Improved naming of data conversion methods in Form and made th…
Mar 20, 2011
acaa9c9
[Form] Fixed signature of Form::addError()
Mar 20, 2011
4989e96
[Form] Moved form type tests into according namespace
Mar 20, 2011
61804bb
Merge remote branch 'symfony/master' into experimental
Mar 21, 2011
321d40b
[Form] Decoupled FormBuilder from ThemeInterface
Mar 21, 2011
01a4745
[Form] Improved naming of various interfaces. Renamed DefaultRenderer…
Mar 21, 2011
3985522
[Form] Removed obsolete classes Error and DataError
Mar 21, 2011
255eda5
[Form] Renamed RecursiveFieldIterator to RecursiveFormIterator
Mar 21, 2011
31647d3
[TwigBundle] Changed twig variable from 'this' to 'renderer'
johnwards Mar 21, 2011
c1abf08
[Form] Implemented error bubbling
Mar 21, 2011
1c5bbb5
Merge remote branch 'johnwards/experimental' into johnwards-merge
Mar 21, 2011
002a22d
[Form] Refactoring DateTimeToStringTranformer not to use Configuration
johnwards Mar 21, 2011
d8287a6
Merge remote branch 'bernhard/experimental' into experimental
johnwards Mar 21, 2011
3c80bc3
[Form] Removing use of old class
johnwards Mar 21, 2011
714f217
[Form] Coding conventions and use of the new variables
johnwards Mar 21, 2011
87665bc
[Form] Decoupled FormBuilder from CSRF protection
Mar 21, 2011
7d7c36a
[Form] More sensible constructor variable order
johnwards Mar 21, 2011
27267e8
[Form] Refactoring tests for new DataTransfomer
johnwards Mar 21, 2011
b4406f2
[Form] Removing Configurable from DataTransformers
johnwards Mar 21, 2011
577e106
[Form] Implemented custom mapping of data errors to form fields
Mar 22, 2011
16d65f6
[Form] Moved previously skipped tests from FormTypeTest to FormTest a…
Mar 22, 2011
09da126
[Form] Fixed validation.xml
Mar 22, 2011
33692ea
[Form] Renamed Form::isTransformationSuccessful() to isSynchronized()…
Mar 22, 2011
5a5fdd0
Merge remote branch 'bernhard/experimental' into configuration
johnwards Mar 22, 2011
270a98e
[Form] Added support for types that are not registered in the DIC. Th…
Mar 22, 2011
ea0e5bb
[Form] Renamed FieldTypeInterface to FormTypeInterface
Mar 22, 2011
0ede919
Merge remote branch 'symfony/master' into experimental
Mar 22, 2011
e54973b
[Form] Refactoring Types to use new DataTransfomer interface
johnwards Mar 22, 2011
ef8113c
[Form] Base tests for renderers
johnwards Mar 22, 2011
37f12f6
[Form] The declaration and initialization (constructor) of the variab…
johnwards Mar 22, 2011
2e750f7
[Form] Coding conventions
johnwards Mar 22, 2011
1a014d1
[Form] Tests for Renderer Plugins
johnwards Mar 22, 2011
85701b6
[Form] Missing methods from interfaces
johnwards Mar 22, 2011
9e02544
Merge remote branch 'johnwards/configuration' into configurable-merge
Mar 23, 2011
a880f8d
[Form] Fixed coding conventions
Mar 23, 2011
08a0924
[Form] Fixed order of input and output timezone to a more natural one
Mar 23, 2011
9839aaf
Merge remote branch 'symfony/master' into experimental
Mar 23, 2011
c01419d
Merge remote branch 'johnwards/renderer_tests' into renderer-tests-merge
Mar 23, 2011
f71ae03
[Form] AbstractType::getParent() returns 'form' by default now
Mar 23, 2011
1efd680
[Form] Changed naming of Themes to ThemeEngines. Theme templates are …
Mar 23, 2011
1aa34b7
[Form] Fixed more naming of themes and theme engines
Mar 23, 2011
9b67222
[Form] Improved internal structore of PropertyPathMapper
Mar 23, 2011
5078a63
Revert "[Form] Fixed more naming of themes and theme engines"
Mar 24, 2011
5b41810
Revert "[Form] Changed naming of Themes to ThemeEngines. Theme templa…
Mar 24, 2011
1211d77
[Form] Introduced renderer theme factories so that themes can be chan…
Mar 24, 2011
2faa47d
[Form] Added fallback templates to TwigThemeFactory
Mar 24, 2011
0b4c3c0
[Form] Fixed coding conventions
Mar 24, 2011
15d5259
[Form] Forms now remember the types used during their construction
Mar 24, 2011
6bcc049
[Form] Introduce ArrayTypeLoader, Remove EntityManager and FormFactor…
beberlei Mar 24, 2011
8d6dd2b
[Form] Add Arbitrary Attribute Support to Form Rendering.
beberlei Mar 24, 2011
1ff6906
[Form] Simplified ArrayTypeLoader and used it as base class of Defaul…
Mar 24, 2011
ee96ad0
[Form] [DoctrineBridge] Move EntityType and DoctrineTypeLoader into D…
beberlei Mar 23, 2011
3f390aa
[Form] Removed EntityType from DefaultTypeLoader
Mar 24, 2011
ef334db
Merge remote branch 'beberlei/AttributeSupport' into beberlei-merge
Mar 24, 2011
50642bb
[Form] Added EntityType DIC configuration to DoctrineBundle
Mar 24, 2011
262bdcb
[Form] Fixed validation
Mar 24, 2011
66ba0c3
[Form] Fixed: vars are initialized when ThemeRenderer::getVars() is a…
Mar 24, 2011
d84d167
[Form] Fixed display of enctype for file fields in Twig theme
Mar 24, 2011
4372bd5
[Form] Fixed: Bubbling errors are caught correctly
Mar 24, 2011
d2b0705
[Form] CSRF token is now only validated for root form
Mar 24, 2011
770d403
[Form] Improved error mapping in DelegatingValidator
Mar 24, 2011
4c43aa0
[Form] Fixed: Elements are removed from collections when a 'collectio…
Mar 25, 2011
729438f
Merge branch 'rename-execute' into experimental
Mar 25, 2011
ec38901
Merge branch 'rename-execute' into experimental
Mar 25, 2011
3c412ff
[Form] Moved Form::validateData() to DelegatingValidator::validateFor…
Mar 25, 2011
9b1b8cb
[Form] Replaced various occurences of 'field' by 'form'
Mar 25, 2011
40ee22c
[Form] Fixed call to DataEvent::getForm() in Doctrine bridge
Mar 25, 2011
9c4095a
[FrameworkBundle] AddFormTypesPass now uses the service ID as alias i…
Mar 25, 2011
7b412cc
[Form] Removed FormFactory::addGuessers() and moved guessers to const…
Mar 25, 2011
eb18676
Merge branch 'master' into experimental
Mar 25, 2011
e3ac248
[Form] Errors are mapped to subforms correctly and bubble up again if…
Mar 25, 2011
6825ea2
[Form] Improved test coverage of PropertyPathMapper
Mar 25, 2011
0ace068
[Form] PropertyPathMapper now only maps if the form data is synchroni…
Mar 25, 2011
7585dce
[Form] Added options validation to field creation
webmozart Mar 25, 2011
18b9835
Merge branch 'master' into experimental
webmozart Mar 25, 2011
73d8470
[Form] Fix children implementation, setChildren() is not used, the at…
beberlei Mar 26, 2011
cd1ce86
[Form] Iterator support for ThemeRenderer
beberlei Mar 26, 2011
f882a51
[Form] Initialize on iterator access.
beberlei Mar 26, 2011
41c3aea
Merge remote branch 'beberlei/FormRendererItrator' into beberlei-merge
webmozart Mar 26, 2011
d87651b
[Form] Add option "prototype" defaulting to true.
beberlei Mar 26, 2011
f9e2864
[Form] Set prototype to true by default.
beberlei Mar 26, 2011
a396f8f
Merge remote branch 'symfony/master' into experimental
webmozart Mar 26, 2011
c786fac
[Form] Sample fix implementation of renderers
Mar 24, 2011
8c7a93c
[Form] Added FormTypeInterface::buildRendererBottomUp() which is call…
webmozart Mar 25, 2011
fae319e
[Form] Renderers are now created explicitely using FormFactory::creat…
webmozart Mar 26, 2011
ed69d7f
[Form] Fixed rendering using the PHP Templating engine
webmozart Mar 26, 2011
9ff91dc
Merge remote branch 'beberlei/FormsCollectionPrototype' into beberlei…
webmozart Mar 26, 2011
a58cfab
[Form] Removed form.type.loader tag and according compiler pass to si…
webmozart Mar 26, 2011
89361d0
[Form] Renamed FormType::configure() to FormType::buildForm()
webmozart Mar 26, 2011
c891e40
Merge remote branch 'symfony/master' into experimental
webmozart Mar 26, 2011
eaff9c6
[Form] Fixed: the default template is only set on the root renderer a…
webmozart Mar 26, 2011
b219294
[Form] Completely removed the fields variable in the renderer. The re…
webmozart Mar 27, 2011
67d85c6
[Form] Fixed signature of FormThemeInterface::render()
webmozart Mar 27, 2011
dc38eef
[Form] Changed the default value of the 'property_path' option to NUL…
webmozart Mar 27, 2011
364b0f5
[Form] Fixed: FormBuilder::add() accepts FormTypeInterface instances
webmozart Mar 27, 2011
6588a47
[Form] Removed FormBuilder::setDataClass(). Use the FieldType option …
webmozart Mar 27, 2011
80116be
[Form] Removed unused 'template' option
webmozart Mar 27, 2011
5ac979b
[Form] Fixed default value of 'validation_groups' option, removed dup…
webmozart Mar 27, 2011
b180319
[Form] Moved creation of empty data to Form to clean up DataMapperInt…
webmozart Mar 27, 2011
29d412c
[Form] Changed name of VirtualFormIterator to VirtualFormAwareIterator
webmozart Mar 27, 2011
edfae73
[Form] Moved PropertyPath, PropertyPathIterator and VirtualFormAwareI…
webmozart Mar 27, 2011
58b8555
[Form] Removed unused use-statements
webmozart Mar 27, 2011
8a981dd
[Form] Removed unused variable
webmozart Mar 27, 2011
7006202
Merge remote branch 'symfony/master' into experimental
webmozart Mar 27, 2011
cfaa03e
[Form] Fixed: empty objects are only created upon binding forms with …
webmozart Mar 27, 2011
4ec6ba8
[Form] Fixed: set data is treated as string except if a transformer i…
webmozart Mar 27, 2011
1fa004c
[Form] Simplified the interface names of the Renderer subnamespace
webmozart Mar 27, 2011
65f58c9
[Form] Introduced generic RendererInterface
webmozart Mar 27, 2011
0fb95c1
Merge remote branch 'symfony/master' into experimental
webmozart Mar 27, 2011
e7df781
[Form] Fixed calls to ThemeRenderer::renderPart()
Mar 28, 2011
53838ab
Merge remote branch 'symfony/master' into experimental
webmozart Mar 28, 2011
544f763
[FrameworkBundle][TwigBundle] Adapted bundle references to latest sym…
webmozart Mar 28, 2011
55c1468
Merge remote branch 'symfony/master' into experimental
webmozart Mar 30, 2011
60f0486
Merge remote branch 'symfony/master' into experimental
webmozart Mar 30, 2011
a1fc882
[Form] fixed DefaultFormFactory
fabpot Mar 30, 2011
b219e92
[Form] fixed Twig theme tests
fabpot Mar 31, 2011
c7ccb66
[Form] removed unused constructor argument from Type\FieldType (theme…
fabpot Mar 31, 2011
30f26ed
[Form] changed DefaultFormFactory to be more 'useable'
fabpot Mar 31, 2011
59ef0c9
[Form] fixed two unit tests
fabpot Mar 31, 2011
bbeddf7
Merge remote branch 'symfony/master' into experimental
webmozart Mar 31, 2011
1ef1836
[Form] Made name immutable in FormBuilder to avoid synchronization pr…
webmozart Mar 31, 2011
c864d7f
[Form] Improved test coverage of Form class
webmozart Mar 31, 2011
33b0011
[Form] Improved test coverage of Form
webmozart Apr 2, 2011
ca20aef
[Form] Improved test coverage of DelegatingValidator and fixed valida…
webmozart Apr 2, 2011
4f39234
[Form] bind() is ignored if a form is read-only
webmozart Apr 2, 2011
35d9b7f
[Form] Improved test coverage of Form. The emptyValue closure now rec…
webmozart Apr 2, 2011
39b0aaf
Merge remote branch 'symfony/master' into experimental
webmozart Apr 2, 2011
37e8e12
[Form][FrameworkBundle][TwigBundle] Renamed view variable 'disabled' …
webmozart Apr 2, 2011
94f2baa
[Form] Fixed BooleanToStringTransformer::reverseTransform() to accept…
webmozart Apr 2, 2011
d3c8647
[Form] Fixed EntitiesToArrayTransformer::reverseTransform() to accept…
webmozart Apr 2, 2011
d3b7c4e
[Form] Moved getLabel(), isChoiceSelected() and isChoiceGroup() from …
webmozart Apr 2, 2011
a4bbc40
[Form] Cleaned up ChoiceListInterface
webmozart Apr 2, 2011
fc59936
[Form] Fixed: ThemeRenderer::isChoiceSelected() works correctly for b…
webmozart Apr 2, 2011
be9ef42
[Form] Renamed choice transformers for better clarity
webmozart Apr 2, 2011
a5d0b3a
[Form] Changed FormBuilder::set(Client|Norm)Transformer to FormBuilde…
webmozart Apr 2, 2011
72a41f8
[Form] Fixed: Booleans can be used as choice keys now
webmozart Apr 2, 2011
0cf8cc7
Merge remote branch 'symfony/master' into experimental
Apr 4, 2011
bfa3c71
[Form] Added Bundle suffixes again
Apr 4, 2011
e476231
[Form] Removed invalid tests, cleaned up some tests, added test coverage
webmozart Apr 6, 2011
3482ff7
[Form] Fixed empty value in choice fields
webmozart Apr 6, 2011
67582c9
Merge remote branch 'symfony/master' into experimental
webmozart Apr 6, 2011
dfa1da0
[Form] removed unused use statement and fixed phpdoc
fabpot Apr 7, 2011
7f22943
[Form] reverted the templating part to be similar to what we have today
fabpot Apr 7, 2011
49dc836
[Form] moved the template context creation to the Form class
fabpot Apr 13, 2011
7913d79
[Form] removed DefaultFormFactory as it does not help that much and a…
fabpot Apr 13, 2011
2a18be1
Merge remote branch 'symfony/master' into experimental
webmozart Apr 13, 2011
0b0535d
[Form] Fixed fatal error in test
webmozart Apr 13, 2011
8031ad7
Merge remote branch 'fabpot/form' into fabpot_merge
webmozart Apr 13, 2011
96f040c
[Form] Added extensive test coverage for div_layout.html.twig
webmozart Apr 14, 2011
602846f
[Form] Added tests for table_layout.html.twig
webmozart Apr 14, 2011
ce5f307
Fixed test suite and names of accessor methods in TemplateContext
webmozart Apr 14, 2011
c2dcebf
[FrameworkBundle] Added test coverage for FormHelper and fixed variou…
webmozart Apr 14, 2011
4c0d53a
[TwigBundle] Merged div_layout.html.twig and widget.html.twig
webmozart Apr 14, 2011
4907c7d
[Form] Added test coverage for expanded choice fields
webmozart Apr 14, 2011
ca6ae09
[Form] Removed TemplateContext::create()
webmozart Apr 14, 2011
72b17cd
[Form] Renamed TemplateContext to FormView
webmozart Apr 14, 2011
44af72b
Merge remote branch 'symfony/master' into experimental
webmozart Apr 14, 2011
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
275 changes: 275 additions & 0 deletions src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Form\ChoiceList;

use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\NoResultException;

class EntityChoiceList extends ArrayChoiceList
{
/**
* @var Doctrine\ORM\EntityManager
*/
private $em;

/**
* @var Doctrine\ORM\Mapping\ClassMetadata
*/
private $class;

/**
* The entities from which the user can choose
*
* This array is either indexed by ID (if the ID is a single field)
* or by key in the choices array (if the ID consists of multiple fields)
*
* This property is initialized by initializeChoices(). It should only
* be accessed through getEntity() and getEntities().
*
* @var Collection
*/
private $entities = array();

/**
* Contains the query builder that builds the query for fetching the
* entities
*
* This property should only be accessed through queryBuilder.
*
* @var Doctrine\ORM\QueryBuilder
*/
private $queryBuilder;

/**
* The fields of which the identifier of the underlying class consists
*
* This property should only be accessed through identifier.
*
* @var array
*/
private $identifier = array();

/**
* A cache for \ReflectionProperty instances for the underlying class
*
* This property should only be accessed through getReflProperty().
*
* @var array
*/
private $reflProperties = array();

/**
* A cache for the UnitOfWork instance of Doctrine
*
* @var Doctrine\ORM\UnitOfWork
*/
private $unitOfWork;

private $propertyPath;

public function __construct(EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = array())
{
// If a query builder was passed, it must be a closure or QueryBuilder
// instance
if (!(null === $queryBuilder || $queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) {
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder or \Closure');
}

if ($queryBuilder instanceof \Closure) {
$queryBuilder = $queryBuilder($em->getRepository($class));

if (!$queryBuilder instanceof QueryBuilder) {
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
}
}

$this->em = $em;
$this->class = $class;
$this->queryBuilder = $queryBuilder;
$this->unitOfWork = $em->getUnitOfWork();
$this->identifier = $em->getClassMetadata($class)->getIdentifierFieldNames();

// The propery option defines, which property (path) is used for
// displaying entities as strings
if ($property) {
$this->propertyPath = new PropertyPath($property);
}

parent::__construct($choices);
}

/**
* Initializes the choices and returns them
*
* The choices are generated from the entities. If the entities have a
* composite identifier, the choices are indexed using ascending integers.
* Otherwise the identifiers are used as indices.
*
* If the entities were passed in the "choices" option, this method
* does not have any significant overhead. Otherwise, if a query builder
* was passed in the "query_builder" option, this builder is now used
* to construct a query which is executed. In the last case, all entities
* for the underlying class are fetched from the repository.
*
* If the option "property" was passed, the property path in that option
* is used as option values. Otherwise this method tries to convert
* objects to strings using __toString().
*
* @return array An array of choices
*/
protected function load()
{
parent::load();

if ($this->choices) {
$entities = $this->choices;
} else if ($qb = $this->queryBuilder) {
$entities = $qb->getQuery()->execute();
} else {
$entities = $this->em->getRepository($this->class)->findAll();
}

$propertyPath = null;
$this->choices = array();
$this->entities = array();

foreach ($entities as $key => $entity) {
if ($this->propertyPath) {
// If the property option was given, use it
$value = $this->propertyPath->getValue($entity);
} else {
// Otherwise expect a __toString() method in the entity
$value = (string)$entity;
}

if (count($this->identifier) > 1) {
// When the identifier consists of multiple field, use
// naturally ordered keys to refer to the choices
$this->choices[$key] = $value;
$this->entities[$key] = $entity;
} else {
// When the identifier is a single field, index choices by
// entity ID for performance reasons
$id = current($this->getIdentifierValues($entity));
$this->choices[$id] = $value;
$this->entities[$id] = $entity;
}
}
}

public function getIdentifier()
{
return $this->identifier;
}

/**
* Returns the according entities for the choices
*
* If the choices were not initialized, they are initialized now. This
* is an expensive operation, except if the entities were passed in the
* "choices" option.
*
* @return array An array of entities
*/
public function getEntities()
{
if (!$this->loaded) {
$this->load();
}

return $this->entities;
}

/**
* Returns the entity for the given key
*
* If the underlying entities have composite identifiers, the choices
* are intialized. The key is expected to be the index in the choices
* array in this case.
*
* If they have single identifiers, they are either fetched from the
* internal entity cache (if filled) or loaded from the database.
*
* @param string $key The choice key (for entities with composite
* identifiers) or entity ID (for entities with single
* identifiers)
* @return object The matching entity
*/
public function getEntity($key)
{
if (!$this->loaded) {
$this->load();
}

try {
if (count($this->identifier) > 1) {
// $key is a collection index
$entities = $this->getEntities();
return isset($entities[$key]) ? $entities[$key] : null;
} else if ($this->entities) {
return isset($this->entities[$key]) ? $this->entities[$key] : null;
} else if ($qb = $this->queryBuilder) {
// should we clone the builder?
$alias = $qb->getRootAlias();
$where = $qb->expr()->eq($alias.'.'.current($this->identifier), $key);

return $qb->andWhere($where)->getQuery()->getSingleResult();
}

return $this->em->find($this->class, $key);
} catch (NoResultException $e) {
return null;
}
}

/**
* Returns the \ReflectionProperty instance for a property of the
* underlying class
*
* @param string $property The name of the property
* @return \ReflectionProperty The reflection instsance
*/
private function getReflProperty($property)
{
if (!isset($this->reflProperties[$property])) {
$this->reflProperties[$property] = new \ReflectionProperty($this->class, $property);
$this->reflProperties[$property]->setAccessible(true);
}

return $this->reflProperties[$property];
}

/**
* Returns the values of the identifier fields of an entity
*
* Doctrine must know about this entity, that is, the entity must already
* be persisted or added to the identity map before. Otherwise an
* exception is thrown.
*
* @param object $entity The entity for which to get the identifier
* @throws FormException If the entity does not exist in Doctrine's
* identity map
*/
public function getIdentifierValues($entity)
{
if (!$this->unitOfWork->isInIdentityMap($entity)) {
throw new FormException('Entities passed to the choice field must be managed');
}

return $this->unitOfWork->getEntityIdentifier($entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Form\DataTransformer;

use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\DataTransformer\TransformationFailedException;
use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;

class EntitiesToArrayTransformer implements DataTransformerInterface
{
private $choiceList;

public function __construct(EntityChoiceList $choiceList)
{
$this->choiceList = $choiceList;
}

/**
* Transforms entities into choice keys
*
* @param Collection|object A collection of entities, a single entity or
* NULL
* @return mixed An array of choice keys, a single key or
* NULL
*/
public function transform($collection)
{
if (null === $collection) {
return array();
}

if (!($collection instanceof Collection)) {
throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collection\Collection');
}

$array = array();

if (count($this->choiceList->getIdentifier()) > 1) {
// load all choices
$availableEntities = $this->choiceList->getEntities();

foreach ($collection as $entity) {
// identify choices by their collection key
$key = array_search($entity, $availableEntities);
$array[] = $key;
}
} else {
foreach ($collection as $entity) {
$array[] = current($this->choiceList->getIdentifierValues($entity));
}
}

return $array;
}

/**
* Transforms choice keys into entities
*
* @param mixed $keys An array of keys, a single key or NULL
* @return Collection|object A collection of entities, a single entity
* or NULL
*/
public function reverseTransform($keys)
{
$collection = new ArrayCollection();

if ('' === $keys || null === $keys) {
return $collection;
}

if (!is_array($keys)) {
throw new UnexpectedTypeException($keys, 'array');
}

$notFound = array();

// optimize this into a SELECT WHERE IN query
foreach ($keys as $key) {
if ($entity = $this->choiceList->getEntity($key)) {
$collection->add($entity);
} else {
$notFound[] = $key;
}
}

if (count($notFound) > 0) {
throw new TransformationFailedException(sprintf('The entities with keys "%s" could not be found', implode('", "', $notFound)));
}

return $collection;
}
}
Loading