I have follow the logic from AccountBundle .
1. adapt the controller of your entity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private function update ( Website $website , Request $request ) {
return $this -> get ( 'oro_form.model.update_handler' ) -> handleUpdate (
$website ,
$this -> get ( 'sinabs.form.website' ) ,
function ( Website $website ) {
return array (
'route' => 'sinabs_website_update' ,
'parameters' => array ( 'id' => $website -> getId ( ) )
) ;
} ,
function ( Website $website ) {
return array (
'route' => 'sinabs_website_view' ,
'parameters' => array ( 'id' => $website -> getId ( ) )
) ;
} ,
$this -> get ( 'translator' ) -> trans ( 'sinabs.website.controller.saved.message' ) ,
$this -> get ( 'sinabs.form.handler.website' )
) ;
}
2. Create handler for your entity form factory and form select type.
3. Create form factory and form select type
4. You also need to index your entity
Here example of declaration services, implementation could be found in the AccountBundle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sinabs. form. website:
class: Symfony\Componeny\Form\Form
factory_ method: createNamed
factory_ service: form.factory
arguments: ["sinabs_website_form" , "sinabs_website_type" , null]
sinabs. form. handler. website:
class: %sinabs.handler.website.class%
scope: request
arguments:
- @ sinabs. form. website
- @ request
- @ doctrine. orm. entity_ manager
sinabs. form. type. website_ select:
class: %sinabs.form.type.website_select.class%
tags:
- { name: form.type , alias: sinabs_website_select }
sinabs. form. autocomplete. website. search_ handler:
parent: oro_form.autocomplete.search_handler
arguments:
- %sinabs . website. entity. class%
- ["name", "url"]
tags:
- { name: oro_form.autocomplete.search_handler , alias: sinabs_websites_search , acl_ resource: sinabs_website_view }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
search:
Sinabs\ Bundle\ WebsiteBundle\ Entity\ Website:
alias: sinabs_website
label: sinabs.website.entity_plural_label
title_ fields: [name , url]
route:
name: sinabs_website_view
parameters:
id: id
search_ template: SinabsWebsiteBundle :Website :searchResult.html.twig
fields:
-
name: name
target_ type: text
target_ fields: [name]
-
name: url
target_ type: text
target_ fields: [url]