<commit_before>{% use '../CommonAdmin/security_action.php.twig' %}

{% block update_use %}
{% endblock %}

{% block update %}

    public function updateAction($pk)
    {
        ${{ builder.ModelClass }} = $this->getObject($pk);

        {{ block('security_action_with_object') }}

        if (!${{ builder.ModelClass }}) {
            throw new NotFoundHttpException("The {{ model }} with {{ builder.getFieldGuesser().getModelPrimaryKeyName(model) }} $pk can't be found");
        }

        $this->preBindRequest(${{ builder.ModelClass }});
        $form = $this->getEditForm(${{ builder.ModelClass }});
        $form->handleRequest($this->get('request'));

        if ($form->isSubmitted() && $form->isValid()) {
            try {
                {% if concurrency_lock -%}
                $versions = $this->getVersions();
                {% block checkVersion %}// ORM job{% endblock %}
                {%- endif %}

                $this->preSave($form, ${{ builder.ModelClass }});
                $this->saveObject(${{ builder.ModelClass }});
                $this->postSave($form, ${{ builder.ModelClass }});

                $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans("{{ messages.success|default("action.object.edit.success") }}", array(), 'Admingenerator') );

                {% set defaultActionAfterSave = builder.generator.bundleConfig.default_action_after_save %}
                $actionAfterSave = "{{ actionAfterSave|default(defaultActionAfterSave) }}";
                if ($this->get('request')->request->has('save-and-add') || ('new' == $actionAfterSave)) {
                    return new RedirectResponse($this->getNewUrl());
                } else if ($this->get('request')->request->has('save-and-list') || ('list' == $actionAfterSave)) {
                    return new RedirectResponse($this->getListUrl());
                } else if ($this->get('request')->request->has('save-and-show') || ('show' == $actionAfterSave)) {
                    return new RedirectResponse($this->getShowUrl($pk));
                } else {
                    if (('edit' != $actionAfterSave) &&
                        method_exists($this,'get{{ builder.actionAfterSave|default(defaultActionAfterSave)|title }}Url')) {
                        return new RedirectResponse(call_user_func(array($this, 'get{{ builder.actionAfterSave|default(defaultActionAfterSave)|title }}Url'), $pk));

                    }
                    return new RedirectResponse($this->getEditUrl($pk));
                }
            {% if concurrency_lock -%}
            } catch ({% block lockException %}// ORM job{% endblock %} $e) {
                $this->get('session')->getFlashBag()->add(
                    'warning',
                    $this->get('translator')->trans(
                        "{{ messages.locked|default("action.object.edit.locked") }}",
                        array(
                            '%path%' => $this->generateUrl("{{ builder.routePrefixWithSubfolder }}_{{ bundle_name }}{{ builder.BaseGeneratorName ? "_" ~ builder.BaseGeneratorName : "" }}_show", array('pk' => $pk) )
                        ),
                        'Admingenerator'
                    )
                );
                $this->onException($e, $form, ${{ builder.ModelClass }});
                $this->saveVersion($pk, ${{ builder.ModelClass }}->getVersion());
            {% endif %}
            } catch (\Exception $e) {
                $logger = $this->get('logger')->error($e->getMessage());
                $this->get('session')->getFlashBag()->add('error',  $this->get('translator')->trans("{{ messages.error|default("action.object.edit.error") }}", array(), 'Admingenerator') );
                $this->onException($e, $form, ${{ builder.ModelClass }});
            }

        } else {
            $this->get('session')->getFlashBag()->add('error',  $this->get('translator')->trans("{{ messages.error|default("action.object.edit.error") }}", array(), 'Admingenerator') );
        }

        return $this->render('{{ builder.namespacePrefixForTemplate }}{{ bundle_name }}:{{ builder.BaseGeneratorName }}Edit:index.html.twig', $this->getAdditionalRenderParameters(${{ builder.ModelClass }}) + array(
            "{{ builder.ModelClass }}" => ${{ builder.ModelClass }},
            'updateUrl' => $this->getUpdateUrl($pk),
            "form" => $form->createView(),
            'groups' => $this->getGroups(${{ builder.ModelClass }}),
        ));
    }

    /**
     * This method is here to make your life better, so overwrite it
     *
     * @param \Exception $exception throwed exception
     * @param \Symfony\Component\Form\Form $form the valid form
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function onException(\Exception $exception, \Symfony\Component\Form\Form $form, \{{ model }} ${{ builder.ModelClass }})
    {
        if ($this->container->getParameter('kernel.debug')) {
            throw $exception;
        }
    }

    /**
     * This method is here to make your life better, so overwrite  it
     *
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function preBindRequest(\{{ model }} ${{ builder.ModelClass }})
    {
    }

    /**
     * This method is here to make your life better, so overwrite  it
     *
     * @param \Symfony\Component\Form\Form $form the valid form
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function preSave(\Symfony\Component\Form\Form $form, \{{ model }} ${{ builder.ModelClass }})
    {
    }

    /**
     * This method is here to make your life better, so overwrite  it<commit_msg>Update update.php.twig<commit_after>{% use '../CommonAdmin/security_action.php.twig' %}

{% block update_use %}
{% endblock %}

{% block update %}

    public function updateAction($pk)
    {
        ${{ builder.ModelClass }} = $this->getObject($pk);

        {{ block('security_action_with_object') }}

        if (!${{ builder.ModelClass }}) {
            throw new NotFoundHttpException("The {{ model }} with {{ builder.getFieldGuesser().getModelPrimaryKeyName(model) }} $pk can't be found");
        }

        $this->preBindRequest(${{ builder.ModelClass }});
        $form = $this->getEditForm(${{ builder.ModelClass }});
        $form->handleRequest($this->get('request'));
        $this->postBindRequest(${{ builder.ModelClass }});

        if ($form->isSubmitted() && $form->isValid()) {
            try {
                {% if concurrency_lock -%}
                $versions = $this->getVersions();
                {% block checkVersion %}// ORM job{% endblock %}
                {%- endif %}

                $this->preSave($form, ${{ builder.ModelClass }});
                $this->saveObject(${{ builder.ModelClass }});
                $this->postSave($form, ${{ builder.ModelClass }});

                $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans("{{ messages.success|default("action.object.edit.success") }}", array(), 'Admingenerator') );

                {% set defaultActionAfterSave = builder.generator.bundleConfig.default_action_after_save %}
                $actionAfterSave = "{{ actionAfterSave|default(defaultActionAfterSave) }}";
                if ($this->get('request')->request->has('save-and-add') || ('new' == $actionAfterSave)) {
                    return new RedirectResponse($this->getNewUrl());
                } else if ($this->get('request')->request->has('save-and-list') || ('list' == $actionAfterSave)) {
                    return new RedirectResponse($this->getListUrl());
                } else if ($this->get('request')->request->has('save-and-show') || ('show' == $actionAfterSave)) {
                    return new RedirectResponse($this->getShowUrl($pk));
                } else {
                    if (('edit' != $actionAfterSave) &&
                        method_exists($this,'get{{ builder.actionAfterSave|default(defaultActionAfterSave)|title }}Url')) {
                        return new RedirectResponse(call_user_func(array($this, 'get{{ builder.actionAfterSave|default(defaultActionAfterSave)|title }}Url'), $pk));

                    }
                    return new RedirectResponse($this->getEditUrl($pk));
                }
            {% if concurrency_lock -%}
            } catch ({% block lockException %}// ORM job{% endblock %} $e) {
                $this->get('session')->getFlashBag()->add(
                    'warning',
                    $this->get('translator')->trans(
                        "{{ messages.locked|default("action.object.edit.locked") }}",
                        array(
                            '%path%' => $this->generateUrl("{{ builder.routePrefixWithSubfolder }}_{{ bundle_name }}{{ builder.BaseGeneratorName ? "_" ~ builder.BaseGeneratorName : "" }}_show", array('pk' => $pk) )
                        ),
                        'Admingenerator'
                    )
                );
                $this->onException($e, $form, ${{ builder.ModelClass }});
                $this->saveVersion($pk, ${{ builder.ModelClass }}->getVersion());
            {% endif %}
            } catch (\Exception $e) {
                $logger = $this->get('logger')->error($e->getMessage());
                $this->get('session')->getFlashBag()->add('error',  $this->get('translator')->trans("{{ messages.error|default("action.object.edit.error") }}", array(), 'Admingenerator') );
                $this->onException($e, $form, ${{ builder.ModelClass }});
            }

        } else {
            $this->get('session')->getFlashBag()->add('error',  $this->get('translator')->trans("{{ messages.error|default("action.object.edit.error") }}", array(), 'Admingenerator') );
        }

        return $this->render('{{ builder.namespacePrefixForTemplate }}{{ bundle_name }}:{{ builder.BaseGeneratorName }}Edit:index.html.twig', $this->getAdditionalRenderParameters(${{ builder.ModelClass }}) + array(
            "{{ builder.ModelClass }}" => ${{ builder.ModelClass }},
            'updateUrl' => $this->getUpdateUrl($pk),
            "form" => $form->createView(),
            'groups' => $this->getGroups(${{ builder.ModelClass }}),
        ));
    }

    /**
     * This method is here to make your life better, so overwrite it
     *
     * @param \Exception $exception throwed exception
     * @param \Symfony\Component\Form\Form $form the valid form
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function onException(\Exception $exception, \Symfony\Component\Form\Form $form, \{{ model }} ${{ builder.ModelClass }})
    {
        if ($this->container->getParameter('kernel.debug')) {
            throw $exception;
        }
    }

    /**
     * This method is here to make your life better, so overwrite  it
     *
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function preBindRequest(\{{ model }} ${{ builder.ModelClass }})
    {
    }

    /**
     * This method is here to make your life better, so overwrite  it
     *
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function postBindRequest(\{{ model }} ${{ builder.ModelClass }})
    {
    }

    /**
     * This method is here to make your life better, so overwrite  it
     *
     * @param \Symfony\Component\Form\Form $form the valid form
     * @param \{{ model }} ${{ builder.ModelClass }} your \{{ model }} object
     */
    public function preSave(\Symfony\Component\Form\Form $form, \{{ model }} ${{ builder.ModelClass }})
    {
    }

    /**
     * This method is here to make your life better, so overwrite  it
{'fraction_non_alphanumeric': 0.17865016109886384, 'fraction_numerical': 0.0, 'mean_word_length': 2.2664081971752976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7587141', 'n_tokens_mistral': 3282, 'n_tokens_neox': 3087, 'n_words': 577}