Override (almost) any core file in Concrete CMS

Jun 8, 2015

When building complex Concrete CMS sites, you may find yourself needing to change some core functionality. Modern versions of concrete offer a few ways that we can do this without sacrificing updatability or performance.

Disable caching

First, turn off overrides caching via Dashboard > System & Settings > Optimization > Cache & Speed Settings. Until this is turned off Concrete CMS won't look in the application directory unless it knows it has a file in there. This will save you from a lot of headaches when developing and testing these overrides.

Service Provider Overrides

Most of concrete's core functionality is bundled into what we call "services", you can find services in subdirectories of the /concrete/src/ directory.
In order to start these services up, concrete employs a pattern known as "Service Provider". A service provider manages booting up a service and adding it onto our Application instance so if we want to modify what a service is doing, this is the place to start.

For example, what if you wanted to swap the core logger with a custom one?

  1. Open up the core app config group, this is located in /concrete/config/app.php
  2. Find where we list "LoggingServiceProvider" and determine the config key. It looks to be app.providers.core_logging
  3. Open up our application's app config group, this is located in /application/config/app.php
  4. Change app.providers.core_logging to our own custom class

In /application/config/app.php:

<?php

return array(
    'providers' => array(
        'core_logging' => '\Application\Src\Custom\CustomLoggingServiceProvider'
    )
);

Now we've overridden the core logging service provider with our own, but the class we offered CustomLoggingServiceProvider doesn't exist since we just made it up.

In /application/src/Custom/CustomLoggingServiceProvider

<?php
namespace Application\Src\Custom;

class CustomLoggingServiceProvider extends \Concrete\Core\Service\Provider
{

    public function register()
    {
        $my_psr3_logger = new \Some\Custom\Logger();

        $this->app->bind('log', $my_psr3_logger);

        // Set the rest of the bindings that the core sets
        $this->app->bind('Concrete\Core\Logging\Logger', 'log');
        $this->app->bind('Psr\Log\LoggerInterface', 'log');
    }

}

Now instead of the core logging service provider, our own logging service provider is registered and our own custom logger is used everywhere!

Path Based Overrides

Many files can be overridden in concrete simply by providing a file at a specific path. Pretty much the only exclusion to what can be overridden by path is the contents of concrete/src/. Today, we can use paths to override essentially everything that is not a service.

Essentially all path overrides follow an extremely simply pattern: find the path of the file you want to override within the concrete directory, and create a file at that same path within your application directory.

For example:

Core: /concrete/blocks/some_block/view.php
Override: /application/blocks/some_block/view.php

Core: /concrete/js/some_js_file.js
Override: /application/js/some_js_file.js

Overriding Core Block Types

Concrete comes with many useful block types, but sometimes you might want to tweak how a core block functions. Some reasons you might want to override a block include:

  • Override functionality and display
  • Adding a custom template

Override functionality and display

We can add actions, change how things save, and even replace data by overriding a block controller.

For example if we wanted to override the content block to capitalize all content:

In /application/blocks/content/controller.php

<?php
namespace Application\Block\Content;

class Controller extends \Concrete\Block\Content\Controller
{
    public function view()
    {
        $this->set('content', strtoupper($this->getContent()));
    }
}

That's not all we can override, we can do this same thing with any file in the /concrete/blocks/content/ directory. All you need to do is create the file in your /application/blocks/content/ directory!

Adding a Custom Template

Custom Templates allow us to create custom views for blocks that we can optionally enable.

For example, to modify the HTML block to render as code:

In /application/blocks/html/templates/code_block/view.php

<pre><code><?= h(trim($content)) ?></code></pre>

Custom templates can be used to replace any javascript, css, or view files but they cannot be used to replace the controller.

Path Based Examples

  • Themes
    • Core Path: /concrete/themes/theme_handle/page_theme.php
    • Package Path: /packages/package_handle/themes/theme_handle/page_theme.php
    • Override Path: /application/themes/theme_handle/page_theme.php
    • Override Class Name: \Application\Theme\ThemeHandle\PageTheme
  • Blocks
    • Core Path: /concrete/blocks/block_handle/controller.php
    • Package Path: /packages/package_handle/blocks/block_handle/controller.php
    • Override Path: /application/blocks/block_handle/controller.php
    • Override Class Name: \Application\Block\BlockHandle\Controller
  • Attributes
    • Core Path: /concrete/attributes/attribute_handle/controller.php
    • Package Path: /packages/package_handle/attributes/attribute_handle/controller.php
    • Override Path: /application/attributes/attribute_handle/controller.php
    • Override Class Name: \Application\Attribute\AttributeHandle\Controller
  • Authentication Types
    • Core Path: /concrete/authentication/type_handle/controller.php
    • Package Path: /packages/package_handle/authentication/type_handle/controller.php
    • Override Path: /application/authentication/type_handle/controller.php
    • Override Class Name: \Application\Authentication\TypeHandle\Controller
  • Controllers
    • Core Path: /concrete/controllers/single_page/page_name.php
    • Package Path: /packages/package_handle/controllers/single_page/page_name.php
    • Override Path: /application/controllers/single_page/page_name.php
    • Override Class Name: \Application\Controller\SinglePage\PageName
  • Single Pages
    • Core Path: /concrete/single_pages/account/avatar.php
    • Override Path: /application/single_pages/account/avatar.php
  • Elements
    • Core Path: /concrete/elements/account/menu.php
    • Override Path: /application/elements/account/menu.php
  • Compiled CSS
    • Core Path: /concrete/css/image-editor.css
    • Override Path: /application/css/image-editor.css
  • Compiled JS
    • Core Path: /concrete/js/jquery.js
    • Override Path: /application/js/jquery.js
Recent Tutorials
Updating Concrete Themes from Version 8 to Version 9
Nov 24, 2022

This tutorial covers commonly encountered issues when upgrading a Concrete CMS theme from version 8 to version 9

Transferring ownership of an add-on and a theme
Nov 15, 2022
By katzueno.

If you encounter a Concrete CMS add-on or theme that you love but not being maintained, you may want to ask the author to help or take over the add-on or theme. Here is the quick step-by-step guide of how to transfer the ownership.

How to update Add-Ons if not on the Update Add-Ons Menu item
Jul 4, 2022

How to manually download an add-on and update it when your site's core versions isn't considered compatible with the add-on version.

Generate a report with author information and form summaries in Concrete CMS.
May 9, 2022

In Concrete CMS, you can use a form to initiate contact between logged-in users and then create helpful reports. After form submissions are collected, they can be searched, sorted, and exported as a spreadsheet. This tutorial will detail how to add author information to a report using the advanced search.

How to clone and customize Atomik theme
Feb 14, 2022
By linuxoid.

How to clone and customize Atomik theme

Update jQuery to 3.5 on Concrete CMS version 8.5.x
Dec 1, 2021
By hissy.

If you have to take some time to fix your site to work with version 9 and want to update jQuery immediately, you can override it.

Was this information useful?
Thank you for your feedback.