Install content using the Content Interchange Format (CIF)

When installing packages, we often need to create single pages, user attributes, jobs and more. You can do that programmatically using the concrete5 API, but it's ways more easy to do that using XML files in concrete5 Interchange Format. That's what concrete5 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()
    {
        parent::install();
        $this->installXml();
    }

    /*
     * 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 line, you have to write the XML definition of what you want to be installed. You can see how to declare typical concrete5 structures within the xml files found in concrete/config/install/. Additionally, the Exporter package within the concrete5 Migration Tool automatically generates this XML from an existing concrete5 site. Simply create the items you want, export them as XML, and include the XML in your package.

Examples

Loading Conversation