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

Casting is not respected when using different case in templates #10469

Closed
1 task
GuySartorelli opened this issue Aug 25, 2022 · 4 comments · Fixed by #10470
Closed
1 task

Casting is not respected when using different case in templates #10469

GuySartorelli opened this issue Aug 25, 2022 · 4 comments · Fixed by #10470

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented Aug 25, 2022

Affected Version: 4.x

Description

PHP methods and DataObject properties are case insensitive.
If you get some method or property case insensitively in a template, it will render the correct value but will fall back to the default casting.

Steps to Reproduce

In a page class:

class Page extends SiteTree
{
    public function MyHtmlField()
    {
        return '<strong>strongboi</strong>';
    }
}

In a template:

<h2>Correct casting</h2>
$MyHtmlField
<h2>Incorrect casting</h2>
$myHtmlField

Acceptance Criteria

  • The correct casting is applied when you access some property or method with a different case than is defined in PHP code.

PRs

@michalkleiner
Copy link
Contributor

Could this be caused by the mechanism when it's trying to get an existing method, perhaps in a case-sensitive way, and if it doesn't exist it tries to prepend get there and then the casting is not applied because the method name doesn't match with the get prefix?

@GuySartorelli
Copy link
Member Author

GuySartorelli commented Sep 7, 2022

I think the attached PR illustrates the cause pretty well - basically ViewableData::castingHelper() is using isset() to see if the field name is in its casting config - but isset() is case sensitive so of course the following will return false even though the field we want is in the config:

$config = [
    'MyField' => 'Text',
];
isset('myField', $config);

@michalkleiner
Copy link
Contributor

Of course. I missed the link to the PR which I've just approved.

@GuySartorelli GuySartorelli linked a pull request Sep 7, 2022 that will close this issue
@kinglozzer
Copy link
Member

PR merged

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

Successfully merging a pull request may close this issue.

3 participants