Programmatically add a new page type and page type defaults from package

Permalink 2 users found helpful
Hi folks,

I'm developing a package for a Concrete5 managed website. Using Google I learned how to install blocks from a package using

BlockType::installBlockTypeFromPackage('blockName', $pkg);

but found no similar way to install page types from a package and even set its page type defaults.

Is there a straight forward way to achieve this?

I've taken a look at concrete/single_pages/dashboard/pages/types/view.php to see how a page type will be added using the dashboard, but the code in view.php seems very cumbersome.

Many thanks for your help!


View Replies: View Best Answer
PauloCarvalhoDesign replied on at Permalink Best Answer Reply
Here in your controller.php,
// install  page types
           $theme2 = CollectionType::getByHandle('your_page_type');
        if(!$theme2 || !intval($theme2->getCollectionTypeID())){ 
           $theme2 = CollectionType::add(array('ctHandle'=>'your_page_type','ctName'=>t('Your Page Type Name')),$pkg);

Hope this does it for you.
greggy80 replied on at Permalink Reply
Thanks, revolutiumstudio!

That's what I was searching for. Nearly :-)
Can you also tell me how to edit the page type's defaults?

Let's say I want to add a default Block at two Areas of the page type called "1st Block Area" and "2nd Block Area" - generated in the page type php file with

$a1 = new Area('1st Block Area'); $a1->display($c);
$a2 = new Area('2nd Block Area'); $a2->display($c);

What would I do next to your example code?

Many thanks for your support!

PauloCarvalhoDesign replied on at Permalink Reply
Download concrete5 v5.3 and look into the install script, It demonstrates how to add content to default home page.
Althought I would suggest that if you are building a package to be submited to mp, you dont need to do that.
If your happy with the above answer please consider marking it as Best!:)
greggy80 replied on at Permalink Reply
This sort of package is not designated for the Market Place (cuz it's proprietary stuff). :-)
My goal is to provide a package for our sekretary to easily install and subsequently add content to the website without configuring anything - such that she hasn't care of anything but the content.

Concrete5 is basically the best choice since it provides an in-context-editing.

I think it would be ok to configure the defaults after installing the package - but my nerd-spirit wants me to automate this step...

I'll have a look at the installation file - so hopefully I'll get an answer.

Best regards,
PauloCarvalhoDesign replied on at Permalink Reply
Ok in that case you should use defaults in the page types.
after instalation edit the defaults in each page type and after that fro each new page created the blocks will be on the page as default.