getThemeDefaultBlockTemplates() not working anymore?

Permalink
Is it possible that the public function getThemeDefaultBlockTemplates() in page_theme.php of a theme package doesn't work anymore in 8.4.x?

Maybe a change in syntax that i've been missing?

The code that previously worked looks like that:

public function getThemeDefaultBlockTemplates()
    {
        return array(
            'autonav' => 'custom_nav',
            'next_previous' => 'custom_next_prev',
            'file' => 'custom_file',
        );
    }


Just to clarify, the path to my custom block template for "file" in the example above is:

packages/my_theme_package/blocks/file/templates/custom_file/view.php

Namespacing in page_theme.php is ok, it has not been changed since default block templates worked.

Can't tell exactly when it stopped working, i think it happened after one of a concrete5 8.3.x or 8.4.0RCx update.

okapi
 
byvictoria replied on at Permalink Reply
byvictoria
Hi! I have the same problem, I need a custom template for the form block, and I couldn't make it work...
Thank you!
okapi replied on at Permalink Reply
okapi
Just to make sure: it's about setting a custom template as the default one in page_theme.php, not about custom templates in general. Are you definitely experiencing that you defined one of available block templates as default in page_theme.php and that didn't work?

Anyone else can confirm this too?

Thank you!
byvictoria replied on at Permalink Reply
byvictoria
No, I was talking only abaout custom block templates.

Maybe the answer to your issue is here

https://github.com/concrete5/concrete5/pull/6456...

All the best,

V.
okapi replied on at Permalink Reply
okapi
So you mean that this PR changed the syntax of this function, thus it doesn't work anymore?
mnakalay replied on at Permalink Reply
mnakalay
I don't know if this will help but be aware that those templates will only apply to blocks added AFTER they are defined.

If you have blocks already added to your page and you then define those templates in your theme's function, they won't apply. They will only apply to newly added blocks.
okapi replied on at Permalink Reply
okapi
Yes, i'm aware of this.
mnakalay replied on at Permalink Reply
mnakalay
@okapi I thin @byvictoria is correct

I think you can fix it by modifying the file concrete/src/Page/Page.php. At line 2267 you will see
foreach($themeTemplates as $key => $template){
    $pt = ($this->getPageTemplateHandle()) ? $this->getPageTemplateHandle() : 'default';
    if(is_array($template) && $key == $pt){
        $pageTypeTemplates = $template;
    }
    unset($themeTemplates[$key]);
 }

Move the unset() to be inside the if block and it should fix the problem until the core team fixes it. I left them a message for that on that PR page. If you can confirm my code fixes it, maybe you can also comment there?
foreach($themeTemplates as $key => $template){
    $pt = ($this->getPageTemplateHandle()) ? $this->getPageTemplateHandle() : 'default';
    if(is_array($template) && $key == $pt){
        $pageTypeTemplates = $template;
        unset($themeTemplates[$key]);
    }
 }
okapi replied on at Permalink Reply
okapi
@mnakalay
Yeah, this resolves the issue! Thank you!