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

alt. pageclass not honored by pagestype classes #1412

Closed
LostKobrakai opened this issue Sep 27, 2015 · 12 comments
Closed

alt. pageclass not honored by pagestype classes #1412

LostKobrakai opened this issue Sep 27, 2015 · 12 comments

Comments

@LostKobrakai
Copy link

When extending the User class with an custom one $users is stil loading pages as User objects.

@LostKobrakai LostKobrakai changed the title alt. ClassNames not honored by pagestype classes alt. pageclass not honored by pagestype classes Sep 27, 2015
@LostKobrakai
Copy link
Author

This can be circumvented by using $users->setPageClass($templates->get("user")->pageClass); in site/ready.php. But it still works only for an single class, but not for multiple ones, if alternative user templates are used.

@LostKobrakai
Copy link
Author

Ok found one issue with that. It's not going to work for the current user obj wire('user') out of the box:

$users->setPageClass($templates->get("user")->pageClass);
$uid = $user->id;
$pages->uncache($user);
wire('user', $users->get($uid));

@ryancramerdesign
Copy link
Owner

Since User objects are managed by a PagesType class, and a PagesType class is designed just for an object of a specific class, that's what specifies the object type (rather than the template). So it's not currently designed for using different types of objects for something like User. Though it's likely possible and I can look into it further. Have you considered extending the User object with hooks instead?

@LostKobrakai
Copy link
Author

I have, but it has ended in unmaintainable bulks of hooking functions
and I'm also using static functions. I'm now leaving pw's classes
untouched and just use own classes, where additional domain logic is stored.

Since User objects are managed by a PagesType class, and a PagesType
class is designed just for an object of a specific class, that's what
specifies the object type (rather than the template). So it's not
currently designed for using different types of objects for something
like User. Though it's likely possible and I can look into it further.
Have you considered extending the User object with hooks instead?


Reply to this email directly or view it on GitHub
#1412 (comment).

@LostKobrakai
Copy link
Author

I can certainly see you point with the PagesType class managing (currently) only a single type of page, but when using an alternative user template one might also want to use an alternative class for it (can prevent a damn lot of switch/ifelse statements). Additionally $users is a deep part of the processwire api, so I wouldn't want (and maybe even couldn't) add my own custom implementation.

@ghost
Copy link

ghost commented Jul 18, 2016

Do you know of any downsides when overwriting getPageClass in the Users template to return an empty string? This results in PagesLoader autodetecting the page class:

...
'pageClass' => '',  // blank = auto detect
...

@LostKobrakai
Copy link
Author

Depends on how you mean to overwrite that part.

@ghost
Copy link

ghost commented Jul 18, 2016

I added

    public function getPageClass() {
        return '';
    }

to the Users class to overwrite the following from PagesType

    public function getPageClass() {
        if($this->pageClass) return $this->pageClass;
        if($this->template && $this->template->pageClass) return $this->template->pageClass;
        return 'Page';
    }

@LostKobrakai
Copy link
Author

Changing core classes directly is considered bad practice, because it'll break with the next update you're doing. Rather use the code I posted above and just set the pageClass to an empty string.

@ghost
Copy link

ghost commented Jul 18, 2016

Yes, that's right. But would adding this to the core break anything? Because if not, I'd like to create a pull request...

@LostKobrakai
Copy link
Author

You certainly could, but Ryan does not use pull-requests, therefore it'll probably have as much effect as giving this issue some attention. He already stated above that it was not intended to work that way initially.

Also even if it wouldn't break anything, as long as there are only 2 people voting for a change (which you can do on your own) it's hardly a important topic.

@valieand
Copy link

valieand commented May 5, 2017

Can not find where to vote for a change, but I'm +1.

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

No branches or pull requests

3 participants