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

Support for 'when:' and nesting inside kirby builder(?) #9

Closed
francois-gm opened this issue May 1, 2019 · 2 comments
Closed

Support for 'when:' and nesting inside kirby builder(?) #9

francois-gm opened this issue May 1, 2019 · 2 comments
Assignees
Labels

Comments

@francois-gm
Copy link

Hi,

On a side note I have to say that I've been quite impressed by all your plugins so far(!)

So I'm having small issues with the imageradio field. It seems like it does not work when hidden (so either with using the newer 'when' field property or either with putting an imageradio field inside a 'kirby builder').

When doing so, I end up with an error:
'Undefined index: text' (when used with 'when:')
'Undefined offset: 3' (when used inside a 'kirby builder' field)

Has anybody reproduced this?

I wanted to use the imageradio as it's more explicit for grid layout choices :(

@bertwillekens
Copy link

Having the same issue with using it in Kirby Builder.

The issue is caused by an exception that occurs in the 'ratio' prop function:

'ratio' => function($ratio = '1/1') {
$computed = 1;
if (preg_match('/(\d+)(?:\s*)([\/])(?:\s*)(\d+)/', $ratio, $matches) !== false){
$computed = $matches[3] / $matches[1];
}
$computed = $computed * 100;
$ratio = round($computed, 3, PHP_ROUND_HALF_DOWN);
return $ratio;
},

The 'ratio' function is being called multiple times. The first time, it gets the proper ratio value as a parameter. Subsequent times, it is called with its latest return value as the parameter. I.e. first it gets called with "1/2", then it gets called again with 200, causing an exception on line 28.

It seems like the calling code (I suppose Kirby Builder) is messing up by calling the prop function again with its own return value.

This a temporary fix I applied locally:

function ($ratio = '1/1') {
            if (is_numeric($ratio)) {
                return $ratio;
            }
// ...
}

When the function gets called again with its computed numeric value, I'm returning that value.

@sylvainjule sylvainjule self-assigned this Jun 21, 2019
@sylvainjule
Copy link
Owner

Hello,

Thanks for the kind words!

I don't have any issue with the when: attribute with 3.2, have you given it a shot? I'll close this for more clarity in my tickets, feel free to reopen if the problem is still here.

As for the Builder issue, the field should behave properly even when hidden. It seems that the issue is on the Builder's side, you should rather open an issue there. Thank you for the investigation @bertwillekens, and the workaround. I won't add it in the field since there shouldn't be a need for it at all, but it can be of use if Tim doesn't have time to look into it in the near future.

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

3 participants