madeyourday / contao-rocksolid-custom-elements

RockSolid Custom Elements Contao Extension
http://rocksolidthemes.com/de/contao/plugins/custom-content-elements
MIT License
48 stars 12 forks source link

2.4.7 Empty headline is still output in the template #166

Closed Ainschy closed 8 months ago

Ainschy commented 8 months ago

Contao 4.13.37 PHP8.2

Since 2.4.7 empty headlines are displayed in the frontend despite a query in the template.

2024-02-27_12h24_53 2024-02-27_12h23_27

zoglo commented 8 months ago

I was debugging this for the past few minutes and this is because $this->headline is now of type Stringable and not empty in if-clauses anymore.

image

This is being caused in the last change: https://github.com/madeyourday/contao-rocksolid-custom-elements/blob/c69bf399c9fc6d87ab6114194a0a0ec16bf33466/src/Element/CustomElement.php#L301-L315

The question is if this should be fixed from your side @ausi or if every person using custom-elements would need to update their templates after updating to version 2.4.7.

We'd all either need to use <?php if ((string) $this->headline): ?> or there should be a workaround.

I consider this critical since updates would lead to something that may output empty headlines like here:

<div class="ce_rsce_text col-m-6 text block">
    <div class="inside">
        <div class="c_headline">
            <h1></h1>
        </div>
        <div class="c_text">…</div>
    </div>
</div>

A possible solution would be using the ParseTemplateListener as it only renders html templates


namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Template;

#[AsHook('parseTemplate')]
class ParseTemplateListener
{
    public function __invoke(Template $template): void
    {
        // Cast stringable to string (See #166)
        $template->headline = (string) $template->headline;
    }
}
ausi commented 8 months ago

@Ainschy can you please try if the latest dev-master version fixes your issue?

Ainschy commented 8 months ago

Thanks it's look fine for me

ausi commented 8 months ago

Released as version 2.4.8

@Ainschy @zoglo thank you for the quick reporting/debugging/testing!