monsieurbiz / SyliusCmsPagePlugin

A Sylius plugin to manage your CMS pages
MIT License
37 stars 25 forks source link

remove LocalCode from the CmsPage url #38

Closed rzp-789 closed 1 year ago

rzp-789 commented 2 years ago

I would want to remove the localCode in Url for the page created with this bundle, do you know a way to do this properly ? I tried but everytime i can't refind my CmsPage if i removed the localCode on my Sylius Application. Thanks for your help.

delyriand commented 2 years ago

Hi @rzp-789,

have you tried removing the prefix on route in your config/routes/monsieurbiz_sylius_cms_page_plugin.yaml?

monsieurbiz_cms_page_admin:
    resource: "@MonsieurBizSyliusCmsPagePlugin/Resources/config/routing/admin.yaml"
    prefix: /%sylius_admin.path_name%

monsieurbiz_cms_page_shop:
    resource: "@MonsieurBizSyliusCmsPagePlugin/Resources/config/routing/shop.yaml"
rzp-789 commented 2 years ago

Hi @delyriand , thanks for your answer. And yes it's the first think i did but it's not enough.

maximehuran commented 2 years ago

What is your issue, what happens when you try to go the the URL of your page ? 404 ? 500 ? With more details we will be able to help you more easily.

We managed to disable CMS pages' localized URLs on a project without specific issue.

rzp-789 commented 2 years ago

so i follow this doc to disable local ( https://docs.sylius.com/en/1.9/cookbook/shop/disabling-localised-urls.html ), and i remove prefix like @delyriand recommand me above. I create a page nommed "test". And i get a 404 No route found for "GET https://localhost/test"

maximehuran commented 2 years ago

If you run bin/console debug:router | grep cms what is the result of that ? I can see :

  monsieurbiz_cms_page_show                                                      GET              ANY      ANY    /{slug}

Be sure your route is loaded.

rzp-789 commented 2 years ago

yes i have the same result

 monsieurbiz_cms_page_admin_page_index                                       GET             ANY      ANY    /admin/pages/                                                        
  monsieurbiz_cms_page_admin_page_create                                      GET|POST        ANY      ANY    /admin/pages/new                                                     
  monsieurbiz_cms_page_admin_page_update                                      GET|PUT|PATCH   ANY      ANY    /admin/pages/{id}/edit                                               
  monsieurbiz_cms_page_admin_page_bulk_delete                                 DELETE          ANY      ANY    /admin/pages/bulk-delete                                             
  monsieurbiz_cms_page_admin_page_delete                                      DELETE          ANY      ANY    /admin/pages/{id}                                                    
  monsieurbiz_sylius_cms_page_ajax_generate_page_slug                         GET             ANY      ANY    /admin/page/generate-slug                                            
  monsieurbiz_cms_page_show                                                   GET             ANY      ANY    /{slug} 
rzp-789 commented 2 years ago

we work on a channel with only fr_FR local, maybe come frome there ? because i need to fill the channel when i create my page on admin

delyriand commented 2 years ago

we work on a channel with only fr_FR local, maybe come frome there ? because i need to fill the channel when i create my page on admin

Is your page enabled and assigned to the channel?

rzp-789 commented 2 years ago

yes everything seems good in DB Capture d’écran de 2022-02-16 14-56-45 Capture d’écran de 2022-02-16 14-56-49 Capture d’écran de 2022-02-16 14-56-54

maximehuran commented 2 years ago

Check the https://github.com/monsieurbiz/SyliusCmsPagePlugin/blob/master/src/Routing/PageSlugConditionChecker.php Try to debug on it to check if it's called and if your route condition is :

    condition: "context.checkPageSlug(request)"

Maybe you have another class which decorates router.request_context ?

rzp-789 commented 2 years ago

I think i find something wrong when i dump on vendor/monsieurbiz/sylius-cms-page-plugin/src/Routing/RequestContext.php function checkPageSlug line 79. Capture d’écran de 2022-02-16 15-54-25 i GET True at the condition so it's return "false" Capture d’écran de 2022-02-16 15-53-19

maximehuran commented 2 years ago

Be careful of die on your example because some partial URLs are rendered and they call the context.

rzp-789 commented 2 years ago

ok i want to do but i don't really understand why it's dangerous in this case because nothing is personnal, and finally i found it's this condition on vendor/monsieurbiz/sylius-cms-page-plugin/src/Routing/RequestContext.php => function checkPageSlug line 79. Who return false and doesn't render the page but i would prefere not change the condition ...

rzp-789 commented 2 years ago

i finish by decorate directly router.request_context by mine and change the condition who block me. Thanks for your help ;-).

jacquesbh commented 2 years ago

Hi @rzp-789,

Could you provide the override you've made please? At least we could understand the issue.

Thank you!

rzp-789 commented 2 years ago

I changed the condition who compared 2 object request of function checkPageSlug, by something more specific like the PathInfo maybe it's not the better way but it's functionnal for my project :

/**
     * @param Request $request
     *
     * @return bool
     */
    public function checkPageSlug(Request $request): bool
    {
        if ($request->getPathInfo() !== $this->requestStack->getMainRequest()->getPathInfo()) {

            return false;
        }

        return $this->pageSlugConditionChecker->isPageSlug($this->prepareSlug($request->getPathInfo()));
    }
maximehuran commented 2 years ago

Just a question, did you change the yaml in

image

https://docs.sylius.com/en/1.9/cookbook/shop/disabling-localised-urls.html

With this line I had some issue with this router in my memory, so I removed it :

locale_switcher: storage
rzp-789 commented 2 years ago

yes i changed it, so you tell me without this line i don't need to override the router.request_context ?

maximehuran commented 2 years ago

Yup.

With this line :

image

Without I have a 200 with my page

rzp-789 commented 2 years ago

damn, i loose some much time because of this. Always stay alert with sylius doc. Thanks for your tips

maximehuran commented 2 years ago

We have an issue open on this topic https://github.com/Sylius/Sylius/issues/12227