Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chained properties result in errors if TemplateGlobalProvider returns null #11330

Closed
2 tasks done
GuySartorelli opened this issue Aug 8, 2024 · 0 comments
Closed
2 tasks done
Labels

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented Aug 8, 2024

Module version(s) affected

>= 5.0.0

Description

If a method in a TemplateGlobalProvider returns null, and you chain properties from it, the following error results:

Uncaught Error: Call to a member function obj() on null

Relevant stack trace:

SilverStripe\View\SSViewer_Scope->getObj(Hmm, , 1, )
SSViewer_DataPresenter.php:298

SilverStripe\View\SSViewer_DataPresenter->getObj(Hmm, , 1, )
SSViewer_Scope.php:218

SilverStripe\View\SSViewer_Scope->obj(Hmm, , 1, )
SSViewer_DataPresenter.php:285

SilverStripe\View\SSViewer_DataPresenter->obj(Hmm, , 1)
.cachethemes.simple.templates.Layout.Page.ss:26

include(/var/www/html/silverstripe-cache/gsartorelli/.cachethemes.simple.templates.Layout.Page.ss)
SSViewer.php:576

SilverStripe\View\SSViewer->includeGeneratedTemplate(/var/www/html/silverstripe-cache/gsartorelli/.cachethemes.simple.templates.Layout.Page.ss, PageController, , Array, )
SSViewer.php:648

SilverStripe\View\SSViewer->process(PageController, )
SSViewer.php:642

This seems to be a result of d6e8229 which was originally added in #8456 and rescued from the master branch in #10497

Based on the docs change that was made along side this, it looks like it was intended to be only for passing arguments around, not for intermediate obj() calls.

How to reproduce

Add this TemplateGlobalProvider

<?php

use SilverStripe\View\TemplateGlobalProvider;

class TemplateProvider implements TemplateGlobalProvider
{
    public static function getNullProperty()
    {
        return null;
    }

    public static function get_template_global_variables()
    {
        return ['NullProperty' => 'getNullProperty'];
    }
}

Then add this to any template:

$NullProperty.Hmm.Ohno

Possible Solution

No response

Additional Context

This is a regression - in CMS 4 the null resulted in simply nothing returning in the template (which is how all other null is treated in the template layer).

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)

PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants