Skip to content

Commit

Permalink
you can set your own repository in the mapping class #5
Browse files Browse the repository at this point in the history
  • Loading branch information
asiermarques committed Sep 18, 2017
1 parent 2d2e4f5 commit 9431b6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Form/DataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ class DataMapper implements DataMapperInterface{



public function __construct(EntityManager $entityManager){
public function __construct(EntityManager $entityManager, TranslationRepository $repository=null){

$this->em = $entityManager;
$this->repository = $this->em->getRepository('Gedmo\Translatable\Entity\Translation');

if(!$repository)
$repository = 'Gedmo\Translatable\Entity\Translation';

$this->repository = $this->em->getRepository($repository);

}

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ And now you can work in your controller as if you worked with normal entities
}
}


You can set your own Repository defining a new custom mapping service.
This is useful for instance when you have a [Personal Translation](https://github.com/Atlantic18/DoctrineExtensions/blob/v2.4.x/doc/translatable.md#personal-translations) mapping configuration using a specific translation repository

services:
app.my_custom_mapper:
class: Simettric\DoctrineTranslatableFormBundle\Form\DataMapper
arguments: ["@doctrine.orm.entity_manager", "AppBundle\Repository\PostTranslationRepository"]
app.form.post_type:
class: AppBundle\Form\PostType
arguments: ["@app.my_custom_mapper"]
calls:
- [ setRequiredLocale, [%locale%] ]
- [ setLocales, [%locales%] ]
tags:
- { name: form.type }


If you have configured the Bootstrap Tabs theme in your Twig configuration, you can show your fields with the Boo in the templates with the form_row tag

Expand Down
2 changes: 0 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
services:


sim_trans_form.mapper:
class: Simettric\DoctrineTranslatableFormBundle\Form\DataMapper
arguments: ["@doctrine.orm.entity_manager"]

0 comments on commit 9431b6e

Please sign in to comment.