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

Broader environment variable support #10111

Merged

Conversation

brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Nov 18, 2021

This adds new selectize and selectizeField macros to _includes/forms, which make it easier to create Selectize-based select menus. These support an includeEnvVars setting, which can be set to true to include any defined environment variables which are set to one of the available option values.

{{ forms.selectizeField({
    label: "Encryption Method",
    id: 'encryptionMethod',
    name: 'encryptionMethod',
    options: [
        { value: 'none', label: "None"|t('app') },
        { value: 'ssl', label: "SSL"|t('app') },
        { value: 'tls', label: "TLS"|t('app') }
    ],
    includeEnvVars: true,
    value: adapter.encryptionMethod ?: 'none',
    errors: adapter.getErrors('encryptionMethod'),
}) }}

There’s also new booleanMenu and booleanMenuField macros, which extend selectize/selectizeField for cases where a boolean value is needed. Their options are “Yes” (0) and “No” (1), and support yesLabel and noLabel settings to override the labels.

When includeEnvVars is set to true, they will only include environment variables that are set to a boolean-esque value: on, off, yes, no, true, false, 1, or 0 (case insensitive).

{{ forms.booleanMenuField({
    label: "System Status"|t('app'),
    warning: (craft.app.config.general.isSystemLive is same as(true) or craft.app.config.general.isSystemLive is same as(false) ? configWarning('isSystemLive')),
    id: 'live',
    name: 'live',
    yesLabel: 'Online'|t('app'),
    noLabel: 'Offline'|t('app'),
    includeEnvVars: true,
    value: system.live
}) }}

There’s also a new Craft::parseBooleanEnv() method, which should be used to normalize a boolean menu’s value to true or false at runtime (but that normalized value should not be stored, as we don’t want to lose the original environment variable name).

The following settings have been updated to support environment variables:

  • General → System Status
  • General → Time Zone
  • Email → Encryption Method (SMTP transport type)

A screenshot of the System Status setting page, expanded to show environment variable options

Resolves #8866
Resolves #8989
Possibly alleviates #9855

@linear
Copy link

linear bot commented Nov 18, 2021

DEV-48 Broader environment variable support

CleanShot 2021-06-23 at 08.12.32@2x.png

CleanShot 2021-06-23 at 08.12.59@2x.png

Can be implemented similar to how Zapier allows you to select custom values (e.g. based on prior steps’ variables) for non-textual fields.

@brandonkelly brandonkelly changed the title Feature/dev 48 broader environment variable support Broader environment variable support Nov 18, 2021
@brandonkelly brandonkelly merged commit 22f5cc3 into develop Nov 18, 2021
@brandonkelly brandonkelly deleted the feature/dev-48-broader-environment-variable-support branch November 18, 2021 07:25
@Mosnar
Copy link
Contributor

Mosnar commented Nov 23, 2021

@brandonkelly Should this field also include the same disclaimer that other autosuggest fields have?
image

@brandonkelly
Copy link
Member Author

@Mosnar Considered it but it’s a bit more immediately obvious that it’s possible, since all available options are always present in the dropdown (until you start typing), whereas autosuggest fields are limited to just the first five options, which may not be environment variables.

@timeverts
Copy link

This change is revolutionary @brandonkelly! Thanks so much!

@brandonkelly
Copy link
Member Author

Went ahead and added tips to these new settings as well, in 3.7.23 (see #8989 (reply in thread)).

@sjelfull
Copy link
Contributor

@brandonkelly This is awesome! Should be added to Plugin docs.

AugustMiller added a commit to craftcms/docs that referenced this pull request Aug 22, 2023
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.

None yet

4 participants