When installing packages, we often need to create single pages, user attributes, jobs and more. You can do that programmatically using the Concrete CMS API, but it's ways more easy to do that using XML files in Concrete Interchange Format. That's what Concrete does in the install procedure.
Add these lines of code to the controller.php
file of your package:
/*
* Method called when the package is installed.
*/
public function install()
{
$pkg = parent::install();
$this->installXml();
return $pkg;
}
/*
* Method called when an installed package is upgraded to a newer version.
*/
public function upgrade()
{
parent::upgrade();
$this->installXml();
}
/**
* Install/update data from install XML file.
*/
private function installXml()
{
// install.xml lives in the root of the package.
$this->installContentFile('install.xml');
}
The concrete5-cif
XML file must start with
<?xml version="1.0"?>
<concrete5-cif version="1.0">
and end with
</concrete5-cif>
Between these lines, you have to write the XML definition of what you want to be installed. You can see how to declare typical Concrete structures within the XML files found in `concrete/config/install/``. Additionally, the Exporter package within the Concrete Migration Tool automatically generates this XML from an existing Concrete site. Simply create the items you want, export them as XML, and include the XML in your package.
Potential pitfalls
Block types, attribute, and other relatively simple objects will not be imported again if they already exist.
Page types, however, have a significant amount of content associated with them so they do not import the same way as simpler objects. They will be imported without checking to see if they already exist which can result in duplicated block type content on the page type, and duplicated controls in the forms. Be sure to manage their installation and upgrade process accordingly (see an example here).