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 using config variables in yaml config #137

Open
FrittenKeeZ opened this issue Jan 28, 2025 · 8 comments
Open

Support for using config variables in yaml config #137

FrittenKeeZ opened this issue Jan 28, 2025 · 8 comments
Labels

Comments

@FrittenKeeZ
Copy link

Description

Before migrating to v5 we could use dynamic audience_id based on our environment using the env:

'audience_id' => env('MAILCHIMP_AUDIENCE_ID'),

After upgrading I wanted to accomplish the same using the config, but it breaks everything because the config value isn't being replaced

audience_id: '{{ config:mailchimp:audience_id }}'

Taken from API call:

"lists/{{ config:mailchimp:audience_id }}"

Steps to reproduce

  1. Add audience_id to mailcihmp.php config
    'audience_id' => env('MAILCHIMP_AUDIENCE_ID'),
  2. Change audience_id in newsletter.yaml to use config
    audience_id: '{{ config:mailchimp:audience_id }}'
  3. Navigate to /cp/forms/newsletter/edit
  4. See that you get a fatal error
    StatamicRadPack\Mailchimp\Fieldtypes\MailchimpField::callApi(): Return value must be of type ?array, bool returned

Environment

Environment
Application Name: Odeon
Laravel Version: 10.48.27
PHP Version: 8.2.26
Composer Version: 2.8.4
Environment: local
Debug Mode: ENABLED
URL: odeon.test
Maintenance Mode: OFF

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

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / daily
Mail: smtp
Queue: sync
Session: redis

Statamic
Addons: 5
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.46.0 PRO

Statamic Addons
edalzell/forma: 3.0.1
jacksleight/statamic-bard-mutator: 3.0.3
pecotamic/sitemap: 1.4.7
rias/statamic-redirect: 3.9.3
statamic-rad-pack/mailchimp: 5.2.2

@ryanmitchell
Copy link
Contributor

We'd need to do some Antlers::parse()-ing here:

$form->handle() => Arr::removeNullValues([
'id' => Arr::get($data, 'audience_id'),
'marketing_permissions' => collect(Arr::get($data, 'marketing_permissions_field_ids'))

Passing in the config values.

If its something you need feel free to open a PR and we'll review it.

@FrittenKeeZ
Copy link
Author

@ryanmitchell would it make sense to also "lock" the UI like with the API key so you can't select another list?

@ryanmitchell
Copy link
Contributor

Why? The point of the field is its selectable.

@FrittenKeeZ
Copy link
Author

It's just that other fields in the system get locked when using a config or environment variable.

@FrittenKeeZ
Copy link
Author

@ryanmitchell I'm stuck at the display and the "fix" doesn't feel right...

In StatamicRadPack\Mailchimp\ServiceProvider like you suggested:

'id' => (string) Antlers::parse(Arr::get($data, 'audience_id'), ['config' => config()->all()]),

But then also in StatamicRadPack\Mailchimp\Fieldtypes\MailchimpAudience:

$id = (string) Antlers::parse($id, ['config' => config()->all()]);

if (! $list = $this->callApi("lists/{$id}")) {
    return [];
}

Things don't blow up, but the form is still seeing the config value, which I guess is also why the fieldtype change is needed.
Image

@ryanmitchell
Copy link
Contributor

Yep looks like more is needed than what I suggested. Did you look around core to see how its handled there?

@FrittenKeeZ
Copy link
Author

The closest I got was looking at Statamic\Forms\Email but I can't figure out if the Mailchimp addon explicitly setup the values for the additional form fields.

@FrittenKeeZ
Copy link
Author

@ryanmitchell looks like it's something that needs to be added to the core - most likely in Statamic\Forms\Form::hydrate()

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