Trouble creating grandchild theme

I’m trying to create a child theme of the defaultManuscript theme (grandchild theme of the default theme) in OJS v3.1.2, but am facing an issue that is confounding me.

In the init() function of my BNZSEEManuscriptThemePlugin class, I have the following two lines:

$this->setParent(‘defaultmanuscriptchildthemeplugin’);
$this->modifyStyle(‘stylesheet’, array(‘addLess’ => array(‘styles/variables.less’)));

The contents of my styles/variables.less file is as follows (just for testing):

@bg: #222;

For some reason though, this results in me seeing the default theme with a dark background; not the defaultManuscript theme with a dark background as I’d expect.
If I comment out the line with the modifyStyle command though, I see the defaultMansucript theme unchanged.
Not quite sure what I’m doing wrong here. Any help would be much appreciated.

Thanks!

Reagan

Hi @reagan,

If I understand the problem right, you cannot apply your styling modifications from a child of a Manuscript theme, right? I’ve made a testing just as you described and all works well in my case.

Very strange indeed. I’ve placed my code creating a child of the defaultManuscript theme here: Dropbox - File Deleted

Upon loading this theme as is, I get the following results:
image

Upon commenting the $this->modifyStyle('stylesheet', array('addLess' => array('styles/variables.less'))); line in the BNZSEEManuscriptThemePlugin.inc.php file, I get the following results:
image

I’m finding it hard to understand why the inclusion of that one line produces the default theme with a dark background rather than the defaultManuscript theme with a dark background.

Thanks. Yes, now I can reproduce it. This is relevant for grandchild themes - Manuscript theme is a child of the Default.
Filled it out as an issue: modifyStyle() from grandchild removes child's LESS styling · Issue #4704 · pkp/pkp-lib · GitHub

Great! Thanks a lot for your assistance troubleshooting this.

Hi @Vitaliy

It’s been about seven months now. Just wanted to check in to see if any progress has been made in resolving this yet? It’s really holding up our site development and launch.

Warm Regards

Reagan

Hi @reagan,

Can you test it with the new OJS release - 3.1.2-2? The were some changes related to child themes but I don’t remember if about this issue too.

Hi @Vitaliy

I’m giving upgrading a shot, but it seems like quite a big ordeal considering the amount of code that has been changed outside the theme folder, and will take a lot more work. This was actually the reason we are looking at consolidating all of these code changes into a child theme, so that future upgrades are a bit smoother.

Would it be possible at all for you to test this on OJS release 3.1.2-2 at your end, using the troubleshooting information I’ve provided above? So sorry for the trouble.

Regards

Reagan

Hi @Vitaliy

Just wanted to check in to see if you might be able to test this at your end. It will be quite a significant ordeal to attempt an upgrade of our journal’s OJS website.

Regards

Reagan

Unfortunately, I don’t have 3.1.2-2 instance to test. According to the commit and release timing, it should be fixed starting from version 3.1.2-2.

BTW the latest release is 3.1.2-4. You can test it first locally if have doubts. Moreover, you can use local OJS instance for development and debugging of a child theme.

Hi @Vitaliy

Thanks for that suggestion. I made a local copy of our OJS website, upgraded to version 3.1.2-4, and can see that the issue still persists. It has not been fixed.

Regards

Reagan

Sorry, my mistake. I was thinking about similar issue for child themes but related to templates.
I’ve tested and was able to reproduce the problem.

Can you make minor change in the code in your OJS test instance?
What happens if you replace the line 236
$style = array_merge($style, $args);
to
$style = array_merge_recursive($style, $args);
in ThemePlugin.inc.php file, which can be found in folder lib/pkp/classes/plugins/
In the current version of OJS stable branch the correspondent line is here: pkp-lib/ThemePlugin.inc.php at stable-3_1_2 · pkp/pkp-lib · GitHub

Let me know if it would solve the problem.

Just tried your suggestion. It does appear to solve the primary problem but has a few side effects, such as changing a few colours of the defaultManuscript theme. Screenshots of the website before and after making the change are attached below.

BEFORE:
before

AFTER:
after

Just to clarify, these effects are observed in the currently used defaultManuscript theme itself, not the child theme of the defaultManuscript I am testing at the side.

Hmm, looks like default background color is applied.
Can you also test another modification in addition to previous one? These lines:

Should be changed to

if (isset($args['addLessVariables']) && is_array($args['addLessVariables'])) {
	foreach ($args['addLessVariables'] as $addlessVariables) {
		$less->parse($addlessVariables);
	 }
 }

:slightly_smiling_face: Yup, that seems to have fixed it! Thanks a bajillion!

@NateWr, can you look at this thread and proposed fix?

@Vitaliy I haven’t tested it out but it makes sense at first glance. The lines of code should also work in cases where it’s not an array. Try the following:

if (isset($args['addLessVariables'])) {
	foreach ((array) $args['addLessVariables'] as $addlessVariables) {
		$less->parse($addlessVariables);
	 }
 }

@NateWr - I just tried out your code snippet and it seems to work as well.

1 Like

@NateWr, @Vitaliy - I just upgraded our OJS site to v3.2.1.1 and found that this patch has still not been added to the code. Could this be added to the next release so I don’t have to apply this patch after each upgrade? Thanks!

Hi @reagan, can you provide a pull request with this change to the pkp-lib repository? If possible, also provide an example theme where we can test the change.

When you open the pull request, feel free to tag me with @NateWr to be sure that I see it.