ambipierni Posted February 7, 2023 Share Posted February 7, 2023 Hello, I have the following problem, on the page I have several languages and there are pages that have to be seen in different languages, with activating and deactivating from configuration I can solve it, but the "Default" language does not have a check to deactivate. Link to comment Share on other sites More sharing options...
cst989 Posted March 7, 2023 Share Posted March 7, 2023 Is there an answer for this? I would like to know this also. I have considered (and it has been suggested before) that you could add a custom field for disabling the page in the default language. Then throw a 404 easily if that field is checked. However the issue remains with any selectors, find() etc. that are listing pages. They correctly check for the "Active" checkbox for non-default languages, excluding pages in menus etc.. But you would have to manually update any existing selectors to exclude pages with this new field checked. Unless there's a way to modify core selector process and exclude pages at the top level? Maybe with a hook on $pages->find()? I don't know if that's possible. Edit: this is how I've done it, however I suspect I've probably missed something as I've not tested it thoroughly yet... exclude_in_default_language is a checkbox field $this->addHookBefore('PageRender::renderPage', function() { if(!$this->user->isSuperuser() && $this->user->language->id == $this->languages->getDefault()->id && $this->page->exclude_in_default_language == 1) { throw new Wire404Exception(); } }); $this->addHookBefore('Pages::find', function(HookEvent $event) { $selector = $event->arguments(0); if ( !is_int($selector) && /* seemed to run into an issue with selectors like $pages->find(27) which loads the 404 page, this is just here to tackle that */ !empty($selector) && /* not sure why this would ever happen but I think appending with a comma would be an issue if it did */ $this->page->rootParent->id != 2 && /* exclude admin */ $this->user->language->id == $this->languages->getDefault()->id ) { $selector = $event->arguments(0); $selector .= ', exclude_in_default_language<1'; $event->arguments(0, $selector); } }); Edit 2: Pagination might still be a problem, not sure if this works Ideally I'd have used addHookBefore on the Pages:find, but I struggled in that case searching against a field that might not exist. Updated the hook to "before" Link to comment Share on other sites More sharing options...
cst989 Posted March 9, 2023 Share Posted March 9, 2023 I should add that I imagine this whole thing would be better off in a module, and not using a field but some custom way to store and filter the data, however that's not something I have time for at the moment! To me it seems a bit wild that this isn't possible by default. It's kind of like it's more of a "translated from English" module than a multi-lingual site. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now