Develop a simple package in concrete.

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
May 18, 2016

So now we will start work on a package.

1) Create the package directory

First of all, create a directory in the package directory of your application. Your directory name should be whatever your package name is. I will use the directory name sample_package. So now you have the directory structure Concrete/Package/sample_package. Here, concrete is my application name.

2) Create the controller

Create a file in Concrete/Package/sample_package named controller.php. This file will be responsible for installation, uninstall, upgrade, and other functionalities.

Here is sample code:

<?php 

namespace Concrete\Package\SamplePackage;

use Package;

/**
 * This is the main controller for the package which controls the  functionality like Install/Uninstall etc.
 * 
 * @author AN 05/16/2016
 */
class Controller extends Package
{

    /**
     * Protected data members for controlling the instance of the package 
     */
    protected $pkgHandle = 'sample_package'; 
    protected $appVersionRequired = '5.7.5.6';
    protected $pkgVersion = '0.0.1';

    /**
     * This function returns the functionality description ofthe package.
     * 
     * @param void 
     * @return string $description
     * @author AN 05/16/2016
     */
    public function getPackageDescription()
    {
        return t("A package to demo of package development.");
    }

    /**
     * This function returns the name of the package.
     * 
     * @param void
     * @return string $name
     * @author AN 05/16/2016
     */
    public function getPackageName()
    {
        return t("sample package");
    }

    /**
     * This function is executed during initial installation of the package.
     * 
     * @param void
     * @return void
     * @author AN 05/16/2016
     */
    public function install()
    {
        $pkg = parent::install();

        // Install Single Pages
        $this->install_single_pages($pkg);
    }

    /**
     * This function is executed during uninstallation of the package.
     * 
     * @param void
     * @return void
     * @author AN 05/16/2016
     */
    public function uninstall()
    {
        $pkg = parent::uninstall();
    }

    /**
     * This function is used to install single pages.
     * 
     * @param type $pkg
     * @return void
     * @author AN 05/16/2016 
     */
    function install_single_pages($pkg)
    {
        $directoryDefault = SinglePage::add('/dashboard/sample_package/', $pkg);
        $directoryDefault->update(array('cName' => t('Sample Package'), 'cDescription' => t('Sample Package')));
    }

}

So you can see there are some basic functions defined in this controller. Don't be confused to see install_single_pages functionality. I will describe it later. So copy this code into your controller.php and save it.

3) Give an icon to your package

If you want (and it's recommended), give your package an icon. It is so easy: Put a 97px X 97px .png image in your package folder (Concrete/Package/sample_package). You must name this image icon.png.

4) Create a directory structure for the controller

Create this directory structure for your controller file:

Concrete/Package/sample_package/controller/single_page/dashboard

Then create a file with the name sample_package.php in the dashboard directory and put this code:

<?php

namespace Concrete\Package\SamplePackage\Controller\SinglePage\Dashboard;

use \Concrete\Core\Page\Controller\DashboardPageController;

defined('C5_EXECUTE') or die(_("Access Denied."));

/**
 * This is the controller for the package which controls the functionality for /dashboard/database/ route.
 * 
 * @author AN 05/16/2016
 */
class SamplePackage extends DashboardPageController
{

    /**
     * Function to set the variables for view.
     * 
     * @param void
     * @author AN 05/16/2016
     */
    public function view()
    {
        // Here you can set variable for view $this->set('nameForView',$variable);
    }
}

5) Create a directory structure for single pages

Create this directory structure for the controller file: Concrete/Package/sample_package/single_page/dashboard/sample_package

Next, create a file with name view.php in the dashboard directory and put any html code.

Example:

Hi Sample package

Now install the package and you will get a menu option "sample package". Click it or add this url after index: /dashboard/sample_package. Your page will be shown. You can customize this according your need.

Let me know if this post need any improvement and have any error.

Thanks.

Recent Tutorials
Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Concrete CMS Caching Guide
Oct 16, 2024

An overview of types of caching in Concrete and considerations when using them.

Redirect all requests to HTTPS
Oct 9, 2024
By myq.

How to follow best practices for a secure web

Upgrade Concrete versions 9.3.1 and 9.3.2
Sep 10, 2024
By myq.

How to get past a bug in versions 9.3.1 and 9.3.2 that prevents upgrading the Concrete core through the Dashboard

How to use Composer with Marketplace extensions
Aug 22, 2024

Composer can be used to manage third-party extensions from the marketplace

Controlling Google Tag Manager Tags Based on Concrete CMS Edit Toolbar Visibility
Aug 13, 2024

This document provides a step-by-step guide on how to control the firing of Google Tag Manager (GTM) tags based on the visibility of the Concrete CMS edit toolbar. It explains how to create a custom JavaScript variable in GTM to detect whether the edit toolbar is present on a page and how to set up a trigger that ensures GTM tags only fire when the toolbar is not visible. This setup is particularly useful for developers and marketers who want to ensure that tracking and analytics tags are not activated during content editing sessions, thereby preserving the accuracy of data collected.

Improvements?

Let us know by posting here.