Add parameter $locale
to editAction and showAction:
public function updateAction(Request $request, $id, $locale)
public function editAction($id, $locale)
edit the “change”-URL in the Update-Form:
'action' => $this->generateUrl('...', array(
'id' => $entity->getId(),
'locale' => $entity->getTranslatableLocale()
)),
Set locale in editAction() and updateAction():
$entity = $em->getRepository('tpointProjectBundle:CostCentre')->find($id);
$entity->setTranslatableLocale($locale);
$em->refresh($entity);
Show-Action: get all languages and translations
$entity = $em->getRepository('...')->find($id);
$repository = $em->getRepository('Gedmo\Translatable\Entity\Translation');
$translations = $repository->findTranslations($entity);
if (!$entity) {
throw $this->createNotFoundException('Unable to find CostCentre entity.');
}
$languages = $em->getRepository('tpointContactBundle:Language')->findTransLangs();
$deleteForm = $this->createDeleteForm($id);
return $this->render('tpointProjectBundle:CostCentre:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
'translations' => $translations,
'languages' => $languages
));
Add the method getTranslatableLocale() muss vorhanden sein:
public function getTranslatableLocale() {
return $this->locale;
}
Edit the .._edit
and .._update
routes (additional parameter: locale)
tpoint_admin_costcentre_edit:
pattern: /{id}/{locale}/edit
defaults: { _controller: "tpointProjectBundle:CostCentre:edit", id:0, locale:en }
tpoint_admin_costcentre_update:
pattern: /{id}/{locale}/update
defaults: { _controller: "tpointProjectBundle:CostCentre:update", id:0, locale:en }
requirements: { _method: post|put }
List all avaliable Languages
<tr>
<th>Id</th>
<td></td>
<td>{{ entity.id }}</td>
</tr>
{% for key,lang in translations %}
<tr>
<th>Label {{key}}:</th>
<td>{{ lang.label }}</td>
<td><a href="{{ path('tpoint_admin_costcentre_edit', { 'id': entity.id, 'locale': key }) }}" title="edit {{key}}"><i class="glyphicon glyphicon-edit"></i> edit</a>
</tr>
{% endfor %}
add Language-Buttons (all Languages)
<div class="btn-group spacing-bottom-md ">
{% for lang in languages %}
<a href="{{ path('tpoint_..._edit', { 'id': entity.id, 'locale': lang.code }) }}" title="edit {{lang.code}}" class="btn btn-default">edit {{lang.code}}</a>
{% endfor%}
</div>