Open damienalexandre opened 7 years ago
Tell me more. You want to enable and disable this in runtime. How would you store the data if it is enable or disabled?
I would like to add this in the Bundle:
/**
* @Route("/on", name="edit_on")
*/
public function onAction()
{
$this->container->get('php_translation.edit_in_place.activator')->activate();
return $this->redirectToRoute('homepage');
}
/**
* @Route("/off", name="edit_off")
*/
public function offAction()
{
$this->container->get('php_translation.edit_in_place.activator')->deactivate();
return $this->redirectToRoute('homepage');
}
At the moment, I tell end user to call this them-self, and adding those action could be convenient.
This does not impact the storage which is the session at the moment, using the default Activator.
The redirectToRoute
part is why I didn't do it in the first place.
Maybe just a new paragraph in the documentation is enough. What to you think?
Okey. I misunderstood. I thought you wanted to disable it for all users. Im 👍
Maybe you can redirect the user back to where he/she came from?
What about adding some sort of toggle to the translation block in the webprofiler toolbar itself?
We could, but it's only working if the feature is used in "dev" environment; which should not be the case from my point of view, as this feature is designed for non technical users :nerd_face:
Yes I agree, but I think it does not have to influence the original feature request. See it as addition ;)
Good to know: we will only use it in non-prod / debug environments, we want to both translate via the "edit in place" for the twig views and "profiler" for the controller translations.
A toggle for this could also be added to the Web UI.
My solution working fine:
Controller Function:
/**
* Attivazione dello strumento di Traduzione
* @Route("/{_locale}/translation" , name="translation_action")
* @IsGranted("ROLE_ADMIN")
* @IsGranted("ROLE_TRADUTTORE")
* @IsGranted("ROLE_ASSISTENTE")
* @Method("GET")
*/
public function translationAction(Request $request){
$session = $this->get('session');
if (!$result = $this->get('php_translation.edit_in_place.activator')->checkRequest($request)) {
$session->set('translation',1);
$this->get('php_translation.edit_in_place.activator')->activate();
}
else {
$this->get('php_translation.edit_in_place.activator')->deactivate();
$session->set('translation',0);
}
return $this->json(array('status' => 'SUCCESS', 'result' => $result));
}
I set session variable translation. In Twig:
{% if app.request.session.get('translation') == 1 %}
<a class="navbar-item bord-right-smoke padding-top-bottom-none" href="javascript:setTranslation()"><i class="fas fa-ban"></i> </a>
{% else %}
<a class="navbar-item bord-right-smoke padding-top-bottom-none" href="javascript:setTranslation()"><i class="fas fa-edit"></i> </a>
{% endif %}
finally a easy jquery to reload the same page:
function setTranslation() {
$.get('{{ app.request.locale }}/translation');
location.reload();
}
I hope to help you
We may ship a small default controller to enable and disable the feature when using the default Activator.
This must be optional (maybe some commented out lines in the routing file?).