Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Small Talk about the Symfony2 Form Component

3,648 views

Published on

  • Dating for everyone is here: ❶❶❶ http://bit.ly/2Q98JRS ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/2Q98JRS ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Small Talk about the Symfony2 Form Component

  1. 1. Form%Component%Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  2. 2. An%Object% Domain%Model%PaCern%Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  3. 3. What%is%an%Object%?% •  Instance%of%a%class%definiHon% •  Related%to%others%objects% –  SeCer%and%GeCer%to%assign%values% –  Values%stored%with%properHes% •  Contains%methods%% % Data$Object$ Service$Object$$ $•  Hold%Business%Data% •  Hold%configura-on%data%•  An%object%has%not%informaHon%about%how% •  Know%how%to%manipulate%data% data%are%loaded.%(Does%not%know%what%an% •  In%most%case,%only%one%instance%of%a% «%id%»%is%)% service.%All%services%are%available%through%•  Many%instance%of%the%same%class% the%Service%Container%% definiHon.% •  This%is%not%a%singleton!% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  4. 4. Data%Object%:%Car%Sample%•  A%car%has% –  A%name%•  A%car%is%linked%to% –  A%main%Engine%:%inline%ediHon% –  A%creaHon%date%•  A%Engine%has%% –  A%name% –  A%power%value% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  5. 5. PropertyPath%&%PropertyPathMapper%•  PropertyPath% –  Read%and%write%a%property%from%an%object% –  Use%the%PHP%ReflecHon%API%•  PropertyPathMapper%% –  Iterate%across%form%definiHon%to%map%:% •  Data%to%Form% •  Form%to%Data% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  6. 6. DataTransformer%•  Transform%the%data%into%an%internal% representaHon%(PHP)%into%a%Form% representaHon%(human).%% –  DateTime%instance%to%«%30/11/1981%»% –  Main%transformers%:%DateTimeTransformer,% EnHtyTransformer,%ChoiceTransformer,%etc%…%•  2%Methods%% –  transform%:%php%=>%human% –  reverseTransform%:%human%=>%php% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  7. 7. Form%Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  8. 8. Standard%Form%Lifecycle%CreaHon% DefiniHon% Binding% View% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  9. 9. Symfony%Form%Lifecycle%FormFactory% FormBuilder% Form% FormView% Type% FormBuilder% Type% createBuilder% getForm% buildView% buildForm% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  10. 10. Key%objects%•  FormFactory$(service)% –  Contains%all%types%available%(tag%form.type)%•  FormBuilder%(data)% –  Contains%nested%informaHon%about%the%form%elements% –  Hold%a%reference%to%the%FormFactory$•  Type$(service/data)% –  Each%form%element%is%a%Type,%even%the%main%Form% •  Create%a%FormBuilder%instance% –  Alter%different%objects%during%the%form%lifecycle% •  FormBuilder% •  FormView%•  Form%(data):%% –  Hold%types%definiHons% –  Hold%the%form%subject% –  Responsible%for%binding%new%data%to%the%object%•  FormView%(data):%% –  contains%informaHon%about%how%to%render%the%form% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  11. 11. Let’s%play!% CarType%and%EngineType%Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  12. 12. CarType%•  Fields$ –  CreatedAt%:%dateHme% –  Name%:%text% –  Engine%:%sonata_demo_form_type_engine% •  Custom%type%to%render%an%Engine%class%•  Outline% –  data_class% –  FormBuilder%% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  13. 13. RescueEngine%Extension%•  RescueEngine%:%choice% –  Custom%data%transformer%to%select%the%correct% engine% –  Inherit%transformer%from%the%choice%type% •  Home%work%:%implement%as%a%custom%type%•  Outline% –  DataTransformer% –  Exercice%:%create%a%dedicated%RescueEngineChoiceType Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  14. 14. Type%Extensions%Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  15. 15. Twig%Template%•  Custom%twig%template% –  No%communicaHon%with%the%current%template% –  ImformaHons%are%defined%inside%a%FormView% instance%(Nested%FormView)%•  Rendering%workflow% –  Helpers%:%form_row,%form_rest,%form_errors%...% –  Block’s%name%:%array%of%concatenated%informaHon% of%form%name%and%type%name%with%inheritance% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%
  16. 16. Custom%Block%•  Found%out%a%valid%name%….%•  Name%:% –  _sonata_demo_form_type_car_rescueEngine_label% –  choice_label% –  field_label% Form%Component%–%Thomas%Rabaix%–%sfPot%13/03/2012%

×