Cannot add Redactor custom styles using theme's page_theme.php file

Permalink 1 user found helpful
Hey there, I'm on Concrete 5.7.3.1. I'm trying to add custom styles in Redactor's drop-down menu for a content block, but it quite simply "doesn't work".

Here's what I did:
1. Followed this tutorial:https://www.concrete5.org/documentation/how-tos/designers/adding-red...
2. My theme is called "power" (lowercase, I don't know if it matters), so the namespace and class lines look like this:
namespace Application\Theme\power;
class PageTheme extends \Concrete\Core\Page\Theme\Theme

3. I took the custom classes themselves straight from the Elemental theme, just for testing. The tutorial uses them as an example too.
4. Uploaded the file, purged the cache, created a Content block, clicked Redactor's custom styles dropdown - and there's nothing there.http://i.imgur.com/xKJ6PGn.png

Here's my page_theme.php:
<?php
namespace Application\Theme\power;
class PageTheme extends \Concrete\Core\Page\Theme\Theme {
    public function getThemeEditorClasses()
    {
        return array(
            array('title' => t('Title Thin'), 'menuClass' => 'title-thin', 'spanClass' => 'titlse-thin'),
            array('title' => t('Title Caps Bold'), 'menuClass' => 'title-caps-bold', 'spanClass' => 'title-caps-bold'),
            array('title' => t('Title Caps'), 'menuClass' => 'title-caps', 'spanClass' => 'title-caps'),
            array('title' => t('Image Caption'), 'menuClass' => 'image-caption', 'spanClass' => 'image-caption')
        );
    }
}

It is placed in <root>/application/themes/power/ folder, with the rest of the theme files.

OrionFOTL
 
jakobfuchs replied on at Permalink Reply
jakobfuchs
I think it's necessary to start the theme name with an uppercase letter (use pascal case if it contains underscores), so you should give that a try first.

It's strange that the style popup is completely empty, my installation comes with some custom editor styles preinstalled that I can't remove for some reason.
OrionFOTL replied on at Permalink Reply
OrionFOTL
Thanks for your post. I renamed the theme's folder to "Power", re-installed the theme and reapplied it to every page, and Redactor does get the styles from page_theme.php. That's on my local testing machine. I did the same on my actual site, and nothing changed.

My production site used 5.7.3.1, so I upgraded to 5.7.4.2. Now the Custom Styles dropdown has got the preinstalled custom styles, but not the ones I specified in page_theme.php:http://i.imgur.com/KTwzSKu.png
Additionally, the update broke the dashboard - for some bizzare reason, I get an "Access Denied" message in the Dashboard right-side panel:http://i.imgur.com/g5d9ofL.png - although manually going to <root>/dashboard works fine.
jakobfuchs replied on at Permalink Best Answer Reply
jakobfuchs
Sorry I didn't explain this very well.

The convention in Concrete5 is to name the theme folders in lower case (e.g. power, this applies to package folders as well). If it's more than one word use underscores (e.g. powers_theme).

In the namespace declaration the theme name should start with an uppercase letter:

namespace Application\Theme\Power;


If the theme or package name contains more than one word use Pascal case:

namespace Application\Theme\PowerTheme;


Hope this helps and it's possible that the error your are getting is related to this.
OrionFOTL replied on at Permalink Reply
OrionFOTL
Jakob, I believe the source of my theme problem was some weird caching issue. Here's why: both my local testing machine and my live Internet site had the same configuration, i.e. the theme folder name was lowercase "power", the namespace in page_theme.php was uppercase "Power", both were running 5.7.4.2 and had the same theme files. The testing machine successfully pulled the custom styles from the file, but the live site did not. I purged Cloudflare cache and turned off C5's caching, but it still couldn't contact the page_theme.php file.

What I did next was simply duplicating the whole theme folder, changing its name (and the namespace in page_theme.php) to something else, and applying this "new" theme globally. It must've flipped some kind of switch in concrete5 to make it think it's getting a completely new theme, and to access all the "new" files properly. Now it successfully pulls Redactor custom classes from the .php file.

The Dashboard bug is related to something else, because I tried upgrading before I wanted to make custom classes, and the same issues occurred. I don't feel the need to upgrade to 5.7.4.2, so I'll continue to sit on 5.7.3.1 for now.

Thanks or your help!