Overriding container icons

I’m trying to override container icons. I put them in
application/images/icons/containers/my_container_icon.png

If I save them into
concrete/images/icons/containers/my_icon.png they show up properly and work fine.

can I override images at all?

Just stuff I would try in case you haven’t already…

  1. Make sure Dashboard → Cache and Speed Settings → Overrides Cache is set to off.
  2. Clear Cache
  3. Delete everything under application\files\cache leaving an empty \cache folder

Thanks you mhawke, I tried all your suggestions without success.

It seems that this is not possible in concrete.
– unless somebody knows otherwise.

Any news on that? Is it resolved?
i’d be interested in that. We wanted to have our clients to choose their container easily with help of a colored icon.
It only works when placed in the core folder. But it’ll be overwritten when you update the core.
How can we achieve this?

Hello,

I’m interested too !!

@zoeDC @carmel @JulienSepteo
Icons are not overrideable by just copying files.
But you can always override some classes where the path is hard-coded and provide new path.

A. Open public/application/bootstrap/app.php
and paste this code:

// Autoload custom classes from "public/application/src" directory
$strictLoader = new \Concrete\Core\Foundation\Psr4ClassLoader();
$strictLoader->addPrefix('Application', DIR_APPLICATION . '/' . DIRNAME_CLASSES);
$strictLoader->register();

// Override IconRepository class
$app->bind(
    \Concrete\Core\Page\Container\IconRepository::class,
    \Application\Page\Container\IconRepository::class
);

If you have installed Concrete through Composer, you do not have to use Psr4ClassLoader, since you are propably already able to load classes from src directory.

B. Copy folder
public/concrete/images/icons/containers
to wherever you want.
For example you can copy it to:
public/application/images/icons/containers

You can also add new icons there if you want.

C. Create file:
public/application/src/Page/Container/IconRepository.php
and put inside:

<?php

namespace Application\Page\Container;

use Concrete\Core\Page\Container\IconRepository as CoreIconRepository;

class IconRepository extends CoreIconRepository
{
    public function getPath()
    {
        return DIR_APPLICATION .
            DIRECTORY_SEPARATOR .
            DIRNAME_IMAGES .
            DIRECTORY_SEPARATOR .
            'icons' .
            DIRECTORY_SEPARATOR .
            'containers';
    }

    public function getBaseUrl()
    {
        return '/application/images/icons/containers/';
    }
}

This class is extending original one and is replacing two methods.
getPath() and getBaseUrl() contain addresses to new icons path.
So if you copied icons somewhere else, modify it accordingly.

D. Copy
public/concrete/views/panels/add.php
to
public/application/views/panels/add.php
and replace line 97

src="<?= $container->getContainerIconImage(false) ?>"/></div>

with

src="<?= '/application/images/icons/containers/' . $container->getContainerIcon(); ?>"/></div>

Copy
public/concrete/single_pages/dashboard/pages/containers/view.php
to
public/application/single_pages/dashboard/pages/containers/view.php
and replace line 30

<span><?= $container->getContainerIconImage(); ?></span>

with

 <span><?= new HtmlObject\Image('/application/images/icons/containers/' . $container->getContainerIcon()); ?></span>

You could technically override getContainerIconImage() in entity class (public/concrete/src/Entity/Page/Container.php)
instead overriding those two files above.
But I thought, copying those view files will be easier.

2 Likes

I have opened an issue on GitHub to request a mechanism for adding new Page Template and Container icons. The limited icons available has been a nuisance for many years.

Please add your thoughts to the GitHub issue, or even make a pull request (though bounce your ideas of Andrew before doing code so as to not end up wasting time)

1 Like

@Parasek: Thanks a lot, that is phantastic. Though I have to ask my developer to do that since it seems not just walk in the park.
@JohntheFish: Great that we might have that in the future.

@Parasek: that did the trick. Very nice. Thanks.
@JohntheFish: thanks for adding that to github.