Jump to content

Custom Classes for Page objects - The Discussion


szabesz
 Share

Recommended Posts

Thanks @MarkE - that's basically what I had to do. The difference however is that when hooking on saveReady for a just cloned page, the id is 0 even though it is a valid page and not a null page.

Link to comment
Share on other sites

  • 5 months later...

BasicPagePage.php

class BasicPagePage extends Page { ... }

You take whatever template name you have and convert that to camelcase, eg basic-page = BasicPage, foo-bar = FooBar, home = Home and then you add the suffix Page to that name (FooBarPage, HomePage). In case of BasicPagePage it sounds a bit weird and I've myself done that wrong several times when I forgot the suffix and just called it BasicPage.php and wondered why it is not working. But once you get the concept it's easy and makes sense 🙂 

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

Damned, I have always thought that custom page classes were usable only in template.php files. 🤦‍♂️ This evening I wanted to hack PW to create a template/CustomPageClass mapping usable everywhere with PW API (get, find, etc), and in the first 3 minutes I found it was already there. 😄

This is huge, I love it and am already refactoring some code and twig templates with a custom UserPage, using Traits to share some implementation with my RawUser class (an optimized class from direct database query). I'm quite excited! 😆

  • Like 4
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...