adding attributes on block install?

Permalink
Is it possible to add attributes when a blog is installed rather then having to manually adding them after the fact? Did i miss that in the docs?

jelthure
 
frz replied on at Permalink Reply
frz
you mean you need to create some page attributes for your block to behave right, or something else?
jelthure replied on at Permalink Reply
jelthure
like for when someone downloads my block and installs it on there site I'd like to set it up so they wouldn't have to manually add the attributes.

I was thinking I could just run a sql query on install but wondered if there already was something in place that i should use.
frz replied on at Permalink Reply
frz
page attributes? or default settings in the block?.. where would they have to add them anyway? im confused.
jelthure replied on at Permalink Reply
jelthure
ok so I'm talking about page types and page attributes. I'd like when a person adds my page type to their theme it also adds the required page attributes to the list of availible atts. make sense? sorry I've been awake way too long :)
frz replied on at Permalink Reply
frz
Blocks are encapsulated little guys you should be able to add to any page without any other requirements.

packages (sometimes called applications) are more of what you're looking for.. can include new page types, themes.. etc..

http://www.concrete5.org/index.php?cID=2943...
TheRealSean replied on at Permalink Reply
TheRealSean
Does anyone know the update location for this link?

I would like to be able to create a new page and automatically assign an attribute to that page, is that possible?
jordanlev replied on at Permalink Reply
jordanlev
You mean you want to create a new page from a package installer, create a new attribute, then assign that attribute to that new page?

If so, then try this code (put it in the "install()" function in your package's controller.php file). I haven't tested it but I think it should work:

//Assumes you've already called $pkg = parent::install();
Loader::model('collection_types');
$pageType = CollectionType::getByHandle('page_type_handle'); //<--replace this with the handle for the page type you want this new page to be (left_sidebar, right_sidebar, full, etc.)
$parentPage = Page::getByID(1); //<--assumes you want to create a top-level page (under home page). If you want the new page to appear elsewhere, put in a different id or use Page::getByPath('/path/to/parent/page')
$newPage = $parentPage->add($pageType, array('name' => 'My New Page Title'));
Loader::model('collection_attributes');
$at = AttributeType::getByHandle('text'); //<--replace this with the kind of attribute you want (address, boolean, date_time, iamge_file, number, rating, select, text, textarea, etc.)
$data = array(
    'akHandle' => 'my_attribute_handle',
    'akName' => 'my_attribute_name',
    'akIsSearchable' => true,
);
$ak = CollectionAttributeKey::add($at, $data);
$newPage->setAttribute($ak, 'attribute value');
TheRealSean replied on at Permalink Reply
TheRealSean
I always have trouble keeping on top of replys to my posts,

Thanks for your comments, I sort of mashed something together from various other threads I could find and ended up with this.
On the update and add, functions
$p = Page::getByID($this->post('cID'));
            $parent = Page::getByID($this->post('cParentID'));
            $ct = CollectionType::getByID($this->ctID);            
            $data = array('ctID' =>$ct->getCollectionTypeID(), 
'cDescription' => $this->post('clientsDescription'), 
'cName' => $this->post('clientTitle'), 
'cDatePublic' => Loader::helper('form/date_time')->translate('clientsDate'));
            $p->update($data);
            if($this->post('fID')>0){
               $this->fID = $this->post('fID');
               $fobj = $this->getFileObject();
               $p->setAttribute('page_thumbnail',$fobj);
                                }
                                $p->setAttribute('client_entry',intval(1));