Distribution
PHP Composer Installation for Concrete Packages
Composer Setup for Packages
- Create
composer.json
in your package root withpackage_handle
and settype
toconcrete5-package
. - Register your package on Packagist or add it to the
composer.json
in your Concrete installation underrepositories
.
Including Third-Party Libraries
- Add third-party libraries in
composer.json
underrequire
, like"khill/lavacharts": "2.5.*"
. - Use
composerpkg
to avoid duplicating libraries. - Specify Concrete and PHP versions for compatibility.
Autoloading Code
- Use
getPackageAutoloaderRegistries()
incontroller.php
or theautoload
key incomposer.json
.
Example composer.json
{
"name": "your_name/package_handle",
"type": "concrete5-package",
"require": {
"concrete5/core": ">=8.5.0",
"khill/lavacharts": "2.5.*"
},
"autoload": {
"psr-4": {
"CustomNamespace\\": "src/"
}
},
"config": {
"platform": {
"php": "5.5.9"
}
}
}
Example controller.php
<?php
namespace Concrete\Package\PackageHandle;
use Concrete\Core\Package\Package;
defined('C5_EXECUTE') or die('Access Denied.');
class Controller extends Package
{
protected $appVersionRequired = '8.5.0';
protected $pkgHandle = 'package_handle';
public function install()
{
$this->setupAutoloader();
parent::install();
}
public function on_start()
{
$this->setupAutoloader();
}
private function setupAutoloader()
{
if (file_exists($this->getPackagePath() . '/vendor')) {
require_once $this->getPackagePath() . '/vendor/autoload.php';
}
}
}
Composer Install in Concrete
cd path/to/the/concrete5/root/directory
composer require your_name/package_handle
Prepare for Non-Composer Concrete
cd path/to/the/package/directory
composerpkg install
Publishing Packages in Concrete Marketplace
Manual Publishing
Submit your add-on or theme to the Concrete Marketplace here: https://marketplace.concretecms.com/marketplace/manage_item/.
Automated Publishing with GruntJS
Use "Concrete Package Uploader" for GruntJS for automatic publishing. Configure as follows:
grunt.config.init({
concrete_package_uploader: {
credentials: {
username: "your_username",
password: "your_password"
},
packageInformations: {
packageHandle: "your_package_handle",
packageFile: "build/your_package_file.zip",
title: "My package",
version: '0.9.0',
singlePrice: 15,
keywords: 'some, keywords',
shortDescription: 'This is a short description.',
description: 'This is a long description.',
categories: [16, 50],
screenshots: ["screenshots/1.png", "screenshots/2.png"]
}
}
});
grunt.registerTask('default', ['concrete_package_uploader']);
Install with:
npm install grunt-concrete-package-uploader --save-dev
More information: https://github.com/bitterdev/concrete_package_uploader
Choosing a Method
For one or two packages, manual publishing is suitable. For multiple add-ons or frequent updates, the automated method with GruntJS saves time.