Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove LocalCode from the CmsPage url #38

Closed
rzp-789 opened this issue Feb 15, 2022 · 21 comments
Closed

remove LocalCode from the CmsPage url #38

rzp-789 opened this issue Feb 15, 2022 · 21 comments

Comments

@rzp-789
Copy link

rzp-789 commented Feb 15, 2022

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
Copy link
Member

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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

@maximehuran
Copy link
Member

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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
Copy link
Member

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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
Copy link
Member

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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
Copy link
Member

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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
Copy link
Member

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

@rzp-789
Copy link
Author

rzp-789 commented Feb 16, 2022

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
Copy link
Author

rzp-789 commented Feb 16, 2022

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

@jacquesbh
Copy link
Member

Hi @rzp-789,

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

Thank you!

@rzp-789
Copy link
Author

rzp-789 commented Feb 17, 2022

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
Copy link
Member

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
Copy link
Author

rzp-789 commented Feb 17, 2022

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

@maximehuran
Copy link
Member

Yup.

With this line :

image

Without I have a 200 with my page

@rzp-789
Copy link
Author

rzp-789 commented Feb 17, 2022

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

@maximehuran
Copy link
Member

We have an issue open on this topic Sylius/Sylius#12227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants