Jump to content

using custom page types


valan
 Share

Recommended Posts

There is excellent article here https://processwire.com/docs/tutorials/using-custom-page-types-in-processwire/ by @LostKobrakai that describes how to use custom page types and extend the Page class.

Q: How to extend (e.g. w/o hooks, using method described in article) core Users and User classes and reload $users and $user api variables (they are locked) with new/extended classes? Currently I think about changing User to MyUser class in systems tab (e.g. set another class to be used for 'user' template) and installing module like below. As you can see it adds $myusers and $myuser api variables but I'm not sure that it won't conflict with core.

 

// MyUsers.php
class MyUsers extends Users {

    public function __construct(ProcessWire $wire, $templates = array(), $parents = array()) {
        parent::__construct($wire, $templates, $parents);
        $this->setPageClass('MyUser');
    }

    // my non-overlapping methods here ...
}

// MyUser.php
class MyUser extends User {
    // my non-overlapping methods here ...
}

class ResourceUser extends WireData implements Module {
    public static function getModuleInfo() {
        return [
            'title'    => 'Extend Users and User',
            'version'  => 100,
            'autoload' => true,
            'singular' => true,
        ];
    }

    public function __construct() {
        require_once(dirname(__FILE__) . '/MyUsers.php');
        require_once(dirname(__FILE__) . '/MyUser.php');
    }

    public function init() {
        $pagesType = new MyUsers($this->wire);
        $this->wire('myusers', $pagesType, true);

        $page = new MyUser;
        $this->wire('myuser', $page, true);
    }
}


 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...