Extending Concrete

Improvements?

Let us know by posting here.

Extending Concrete CMS with Custom Code

For tasks beyond Concrete CMS's default capabilities, use core extensions like custom block types, page templates, or elements. Sometimes, custom coding is required, like for a custom page type controller. For instance, to retrieve a list of posts within a custom page type controller view method, consider extending the Concrete\Core\Page\PageList class with a class that filters pages in a specific way. The key is creating this class and placing it correctly in the Concrete filesystem for proper autoloading.

Creating Custom Page Type Controllers

Custom Code in Application Directory

Adding Custom Class

  1. Place the PostList class (extending Concrete\Core\Page\PageList) in application/src/Page/PostList.php.

  2. Use proper namespace:

    namespace Application\Page;
    
    class PostList extends Concrete\Core\Page\PageList
    {
       // Class contents
    }
    
  3. Register namespace in application/bootstrap/autoload.php using a PSR-4 autoloader:

    $classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
    $classLoader->addPrefix('Application\\Page', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Page');
    $classLoader->register();
    

    This maps Application\Page to application/src/Page/.

Adding Custom Doctrine ORM Entities

  1. Place entities in application/src/Entity. Example: application/src/Entity/User/RegistrationRecord.php.

  2. Use correct namespace and import ORM annotations:

    namespace Application\Entity\User;
    use Doctrine\ORM\Mapping as ORM;
    
    /**
    * @ORM\Entity
    * @ORM\Table(name="UserRegistrationRecords")
    */
    class RegistrationRecord
    {
       /**
        * @ORM\Id @ORM\Column(type="integer")
        * @ORM\GeneratedValue(strategy="AUTO")
        */
       protected $id;
    }
    

    This autoloads entities from application/src/Entity.

Including Classes with Composer

Information on integrating Composer in Concrete CMS projects is forthcoming.

Extending Core Classes in Application Directory

Extending Controllers

  • Create controllers in application/ with the same namespace structure as core controllers to extend them. For example:

    namespace Application\Block;
    class Content extends Concrete\Block\Content\Controller
    {
      // Class contents
    }
    

    This applies to block type, attribute controllers, and core view controllers.

Extending Core src/ Classes

To extend core classes in concrete/src/, create a class in application/src/Concrete with a corresponding namespace. Example for extending Captcha controller:

  • Core controller path: src/Captcha/SecurimageController.php
  • Core namespace: Concrete\Core\Captcha\SecurimageController
  • Extended controller path: application/src/Concrete/Captcha/SecurimageController.php
  • Extended namespace: Application\Concrete\Captcha\SecurimageController

Identifying Extendable Items

  • Check the Developer Documentation or the Concrete source for overrideable_core_class() method to identify extendable core classes. This method suggests that the class can be loaded from application/ before trying the core.