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
PagesType::getPageClass not working correctly when PageClass is namespaced #1222
Comments
@sebastiandittrich ProcessWire doesn't currently support Page classes in other namespaces. Though I do think it's likely something we can support at some point if there's a strong need for it. But there may be more drawbacks (especially when it comes to hooks) than benefits at this stage, though I don't know for sure... I've never had a quantity or ambiguity of Page classes where I'd need to start introducing levels of namespaces to them. For your case, since you are already creating a PagesType class, I think you could achieve the same result as your suggested possible fix by overriding the getPageClass method:
While I'm suggesting that as an alternative to what you mentioned, I do want to reiterate that PW just isn't designed for Page classes in some other namespace, so I have no idea how far you can get it doing it. I would be curious what you find though. Thanks. |
I am working with namespaced custom page classes for a while now, but and I haven't encountered any issues with hooks or anything else. This issue is the only point that caused problems. Hooks are anyway not aware of namespaces, as stated here: #109.
I personally don't think that you only need namespaces if you have many pages, but in general when you have a lot of code. Even if there is only one custom page class, I think it makes sense to namespace it. It just gives your code a clean structure and prevents possible naming collisions especially if you are developing a module.
Yes, thanks, this is a valid workaround. But it would be cool if there was native support for namespaced pages in ProcessWire, that's why I've opened this issue. Thank you for your response! |
Glad that override suits your need. It's not technically even a workaround since getPageClass() is a template method, designed to be overridden by a class extending PagesType. So if you find it works, consider it a permanent solution as that method will always be there. I'm going to close this for now since the base PagesType class is working as intended, but if the need arises more feel free to open in the requests repo. |
@BernhardBaumrock If you are overriding the method or doing this with the API, and you find everything continues to work how you want it, then I don't think you'll run into any troubles later. I hadn't tested it myself and so am not as well prepared to provide technical support for it, but I also see no reason why it shouldn't work. If you find it works well then I think we can say that we support it. It may be that I just need to look at the input side in the template editor system tab to make sure namespaces aren't getting sanitized out or something. |
thx @ryancramerdesign , I missed your reply until now... just wanted to support @sebastiandittrich 's statement about using namespaced page classes! I'm using it all the time - it makes all the code so much cleaner, so please have that in mind for whatever you do with the core in the future :) |
Short description of the issue
The
PagesType::getPageClass
method should return the class that was set previously withPagesType::setPageClass
. But it returns an unnamespaced version of the classname.I have the following setup:
Expected behavior
Actual behavior
Possible Fix
Change
false
totrue
in this line: https://github.com/processwire/processwire/blob/master/wire/core/PagesType.php#L607Steps to reproduce the issue
Page
class in different Namespace thanProcessWire\
PagesType
class callingsetPageClass
in the constructor with the createdPage
class.PagesType::get(...)
Page
classSetup/Environment
Server Details
Server Settings
GD Settings
Module Details
The text was updated successfully, but these errors were encountered: