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

Dictionary tag breaks when custom option is not set #11004

Closed
bynicolas opened this issue Oct 24, 2024 · 8 comments
Closed

Dictionary tag breaks when custom option is not set #11004

bynicolas opened this issue Oct 24, 2024 · 8 comments

Comments

@bynicolas
Copy link

Bug description

The new dictionary antler tag introduced in v5.31.0 (#10885) throws a not found exception when a custom option is not set.

I have added a custom multiple toggle option to my dictionary. When the option is not set, the page with the form using that dictionary throws a not found exception.

How to reproduce

in the dictionary definition class, add a custom field option item:

protected function fieldItems()
{
    return [
        'multiple' => [
            'type' => 'toggle',
            'value' => false,
            'instructions' => 'Allow multiple selections.'
        ]
    ];
}

Use the dictionary tag in your form field. I use a form partial defined in resources/views/partials/forms/fields/dictionary.antlers.html dynamically rendered in my form template.

<select name="{{ handle }}{{ dictionary:multiple ?= " []" }}"  ...>
...
</select>

If multiple is not define because the toggle option on the form field is set to disabled, then the exception is thrown

Logs

No response

Environment

Environment
Application Name: Dev site
Laravel Version: 11.28.1
PHP Version: 8.3.12
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: cliniqueia.test
Maintenance Mode: OFF
Timezone: America/Toronto
Locale: fr_CA

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 2
Sites: 2 (Dev site - en)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.31.0 PRO

Statamic Addons
alt-design/alt-redirect: 1.3.2
bynicolas/ignite-seo: dev-main

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@ryanmitchell
Copy link
Contributor

{{ dictionary:multiple }} would be looking for a dictionary called multiple - which doesn't seem right from what you've said?

Should you not just be looking for the multiple variable?

@duncanmcclean duncanmcclean changed the title New disctionary antler tags breaks when custom option is not set New dictionary antler tags breaks when custom option is not set Oct 24, 2024
@duncanmcclean duncanmcclean changed the title New dictionary antler tags breaks when custom option is not set Dictionary tag breaks when custom option is not set Oct 24, 2024
@duncanmcclean
Copy link
Member

duncanmcclean commented Oct 24, 2024

Just to confirm, you're using this in the context of a form field and you're trying to pass a config option to the dictionary? I'm not sure I totally understand the issue.

@bynicolas
Copy link
Author

bynicolas commented Oct 24, 2024

Yes @duncanmcclean, this is used in the context of a form field. The issue is arising in the frontend template when the config option is not set because the toggle is off (false), likely it's trying to access a key that is not set, multiple is the key referencing the toggle's value in my case. The CP is working fine and no problems in adding the the config option to the dictionary

Sorry for not being totally clear, hope this clarifies it a bit more.

@jasonvarga
Copy link
Member

Why are you adding your own multiple field? That's already part of the fieldtype. The "max items" field. As long as you don't set it to 1, it'll allow you to pick multiple.

@bynicolas
Copy link
Author

It was to be consistent with the way select field types are rendered. I am using this option to generate the appropriate template. I am not using the template rendered by default.

Regardless, I think this is a bug introduced since it crashes when rendering the antler tag and the key is not present. Normally antlers would gracefully and silently handle these cases.

In other words, regardless of my use case here, another custom option added to a dictionary field would likely cause the same issue if the field is not set (not tested but I could if you want) and it makes the behaviour expected from antlers inconsistent here. It should handle the exception when a key is not found like it does normally. Well in v5.30.0 and earlier it was working fine.

@Upending36

This comment was marked as spam.

@ryanmitchell
Copy link
Contributor

Did you miss my reply? You are calling dictionary:multiple which will be looking for a dictionary called multiple - which is where the error comes from. That isn’t the name of your variable surely?

@jasonvarga
Copy link
Member

jasonvarga commented Oct 25, 2024

I see your issue.

The actual config of the field has a dictionary key and you want the multiple field inside.

Since you are doing something pretty custom here, I would say just tell Antlers you want the variable and not the tag.

{{ $dictionary:multiple ?= " []" }}

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

No branches or pull requests

5 participants