symfony-bundle icon indicating copy to clipboard operation
symfony-bundle copied to clipboard

[EditInPlace] Add a default controller to enable / disable the editor

Open damienalexandre opened this issue 9 years ago • 9 comments

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?).

damienalexandre avatar Jan 03 '17 17:01 damienalexandre

Tell me more. You want to enable and disable this in runtime. How would you store the data if it is enable or disabled?

Nyholm avatar Jan 03 '17 17:01 Nyholm

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.

damienalexandre avatar Jan 03 '17 17:01 damienalexandre

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?

damienalexandre avatar Jan 03 '17 17:01 damienalexandre

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?

Nyholm avatar Jan 03 '17 17:01 Nyholm

What about adding some sort of toggle to the translation block in the webprofiler toolbar itself?

rvanlaak avatar Jan 04 '17 08:01 rvanlaak

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:

damienalexandre avatar Jan 04 '17 08:01 damienalexandre

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.

rvanlaak avatar Jan 04 '17 08:01 rvanlaak

A toggle for this could also be added to the Web UI.

rvanlaak avatar Jan 04 '17 11:01 rvanlaak

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

sergiotropea avatar May 22 '18 13:05 sergiotropea