• Join Now
  • Sign In
  • Cart
  • Instant Setup
  • Download
Logo
  • About
    • Try it Out
    • For Developers
    • For Agencies
    • For Designers
    • For Anyone
    • Testimonials
    • Showcase
    • History
    • Our Philosophy
    • Credits
    • What does free mean?
    • Blog
  • Community
    • Members
    • Forums
    • Chat
    • Karma
    • International
    • Jobs
    • eNewsletters
  • Developers
    • Download concrete5
    • Join Beta Team
    • Translate concrete5
    • Bug Tracker
    • Submit to Marketplace
    • Code Submissions
    • News
    • Community Leaders
  • Marketplace
    • Add-Ons
    • Themes
    • Add-on Installation
    • Deal Of The Day
    • Swag
    • Theme Contest 2012
  • Services
    • Hosting
    • Support Options
    • Consulting
    • Training
    • Enterprise
  • Documentation
    • Getting Started
    • Editor's Guide
    • Developers Guide
    • How-Tos
  • How-Tos

How to Install PageTypes with Custom Attributes assigned By default from a package

Posted byPauloCarvalhoDesign in Developers on Apr 18, 2011.
12 people like this.

Hello Community, in this tutorial I will show a technique to assign custom attributes to a page type and make them default for that page type.

This is useful for theme developers and I am using a theme packaging example here. So the goal is to make available for the end user custom attributes that you as developer might have created for a specific page type without depending on the user to add a new attribute to the page type.

So from default instalation you will notice that the pagetype (page) has by default the following attributes:

  • Meta Title (id=1)
  • Exclude From Nav(id=2)
  • Meta Description(id=3)
  • Meta Keywords(id=4)

We want to add it to all our pagetypes plus our custom attributes as well. This is how you can do it.

In your package controller load all required models.

Loader::model('collection_types');
Loader::model('collection_attributes');
Loader::model('attribute/categories/collection');

In your controller add a new pagetype example (project):

// install  page types
$theme = CollectionType::getByHandle('project');
if(!$theme || !intval($theme->getCollectionTypeID())){
     $theme = CollectionType::add(array('ctHandle'=>'project','ctName'=>t('Project Page')),$pkg);
}

Now lets add the custom attributes for project pagetype:

$eaku = AttributeKeyCategory::getByHandle('collection');
$eaku->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
$themeSet = $eaku->addSet('built_in',t('Categories Atributes'),$pkg);
 
// install collection attributes
$ak1=CollectionAttributeKey::add($image_file,array('akHandle'=>'project_image','akName'=>t('Project Image'),'akIsSearchable'=>false),$pkg)->setAttributeSet($themeSet);

Note that for the sake of organization I have created a New Set of attributes called built in to keep everything organized and after that I create Project Image attribute.

Now we need to assign our attributes to our pagetype .

$pageType = CollectionType::getByHandle('project');
$ak= CollectionAttributeKey::getByHandle('project_image');
$pageType->assignCollectionAttribute($ak);

Do this for each attribute/page type combination, and the attributes will show up by default when editing the page properties for pages of that type. Many thanks to Andrew for rectifiying this tutorial and Mnkras that gave a correct anwser when I asked in the forums.

How-To Tags

page types, custom attributes, packaging themes

Related How-Tos

None.

  • Documentation
  • How-Tos
  • Developers
  • How to Install PageTypes with Custom Attributes assigned By default from a package

Do you have questions

  • What are users saying?
  • Who is using concrete5?
  • What makes concrete5 easy?
  • Why develop on concrete5?
 

We’re on “The Twitter”

管理画面のJobsはどこにいったかか分かりますか ( #concrete5 live at http://t.co/W3tCUvlA)

Follow concrete5

About

  • Try it Out
  • For Developers
  • For Agencies
  • For Designers
  • For Anyone
  • Testimonials
  • Showcase
  • History
  • Our Philosophy
  • Credits
  • What does free mean?
  • Blog

Community

  • Members
  • Forums
  • Chat
  • International
  • Jobs
  • eNewsletters

Developers

  • Download concrete5
  • Join Beta Team
  • Translate concrete5
  • Bug Tracker
  • Beta
  • Submit to Marketplace
  • Code Submissions
  • News
  • Community Leaders
  • User Doc Group

Marketplace

  • Add-Ons
  • Themes
  • Add-on Installation
  • Deal Of The Day
  • Swag

Services

  • Hosting
  • Support Options
  • Consulting
  • Training
  • Enterprise

Documentation

  • Getting Started
  • Editor's Guide
  • Developers Guide
  • How-Tos

Legal

  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Contact Us
© 2008 to 2012 Concrete CMS Inc. All Rights Reserved.

Sign In?

You must have a user account and be signed to perform this action.

  • Sign In
  • Register