Programmatically set composer settings

Permalink
I have some custom page types which I create during the installation of a package I'm developing. I'd like to also be able to set some default composer settings for these page types, but I can't figure out how to do it (short of manually fiddling with the database, which doesn't seem right).

I sort of expected to be able to pass composer settings as data to CollectionType::add along with ctHandle, ctIcon, etc, but that's unfortunately not correct.

I noticed that CollectionType has an importComposerSettings method, but it's unclear to me what sort of XML it wants and whether it's actually the right thing for the job. I also saw methods like saveComposerAttributeKeys, saveComposerPublishTargetPage, saveComposerPublishTargetPageType, etc but none of these seem to deal with whether the page type is included in composer (the first checkbox on the dashboard composer settings UI) and it feels wrong to be tweaking things one at a time like this.

Any help would be much appreciated.

mkantor
 
mkantor replied on at Permalink Best Answer Reply
mkantor
For anyone else trying to figure out how to do this:

The checkbox to set whether to include the page type in composer doesn't actually set anything in the database, it just determines whether the other fields are saved. So on the new CollectionType you just need to call saveComposerPublishTargetPage() or saveComposerPublishTargetPageType() or saveComposerPublishTargetAll() along with related methods for other composer settings you care about (e.g. saveComposerAttributeKeys()) and the page type will become available in composer.

For example, if you want all attributes assigned to a page type to be settable in the composer and you don't care where the page is published:

public function install() {
   $pkg = parent::install();
   // Create a new page type and give it an attribute.
   $newPageType = CollectionType::add(array(
      'ctHandle' => 'new_page_type',
      'ctName' => 'New Page Type',
   ), $pkg);
   $newAttribute = CollectionAttributeKey::add('boolean', array(
      'akHandle' => 'new_attribute',
      'akName' => 'New Attribute',
   ), $pkg);
   $newPageType->assignCollectionAttribute($newAttribute);
   // Save composer settings for the new page type.
   $newPageType->saveComposerPublishTargetAll();
   // Turn attribute key objects into an array of IDs for saveComposerAttributeKeys.


This is using Concrete5 5.6.0.2.