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

Make Antlers value resolution "lazy", and make pluck operator work with nulls. #7151

Merged

Conversation

JohnathonKoster
Copy link
Contributor

This PR closes #7148

The first fix just checks to make sure that the pluck operator doesn't call the internal Arr::pluck when the incoming value is null.

The second fix makes the evaluation of values "lazy", so that the following only evaluates the tag when value is truthy:

{{ undefined_variable ?= {mytag} }}
<?php

namespace App\Tags;

use Statamic\Tags\Tags;

class Mytag extends Tags
{
    public function index()
    {
        dump('tag is executed');

        return 'test';
    }
}

This lazy evaluation also extends to logic groups, so the following will no longer prematurely set the test variable:

{{ var_exists ?= (test = "testing") }}

{{ test }}

Test cases have been provided for both items 👍

@what-the-diff
Copy link

what-the-diff bot commented Nov 30, 2022

  • LogicGroup is now evaluated as a whole, instead of evaluating the right side first.
  • Added test for pluck on variable that doesn't exist (returns empty string).

@jasonvarga jasonvarga changed the title Antlers: makes value resolution "lazy" Make Antlers value resolution "lazy", and make pluck operator work with nulls. Dec 1, 2022
@jasonvarga jasonvarga merged commit 3e5bade into statamic:3.3 Dec 1, 2022
@jasonvarga jasonvarga deleted the runtime-make-logic-groups-lazy branch December 1, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gatekeeper does execute even when left side is falsey when using pluck
3 participants