how to Install Page Type

Permalink
I want to create page type via controller.php and below code is working in 5.6...

$ct = CollectionType::getByHandle('home');
if((!is_object($ct)) || ($ct->getCollectionTypeID() < 1)) {
$data['ctHandle'] = 'home';
$data['ctName'] = t('Home');
$hpt = CollectionType::add($data, $pkg);
}

What do i do for 5.7

Please help and tell alternative way with example

 
PineCreativeLabs replied on at Permalink Best Answer Reply
PineCreativeLabs
The code you're using is considered deprecated in 5.7+. The code I have below is intended for 8.x, but it works with 5.7.x as well. Here's what you'll need for your package controller:

use Concrete\Core\Page\Theme\Theme;
use PageTemplate;
defined('C5_EXECUTE') or die("Access Denied.");
class Controller extends Package {
public function install() {
        $pkg = parent::install();
   $this->pageTemplates($pkg);
 }
private function pageTemplates($pkg) {
        if (!PageTemplate::getByHandle('home')) {
            PageTemplate::add('home, t('Home') $pkg);
        }
}
}


Notice the private function for creating the page type, and it's checking to see if it already exists and if not, create it.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.