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

Add cast_booleans configuration option to Radio fieldtype #2601

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/lang/da/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Indstil standardværdien.',
'any.config.cast_booleans' => 'Valgmuligheder med værdierne sandt og falsk gemmes som booleanske.',
'array.config.keys' => 'Indstil matrixnøgler (variabler) og valgfri etiketter.',
'array.config.mode' => 'Dynamisk tilstand giver brugeren kontrol over dataene, mens tastetilstand ikke gør det.',
'assets.config.allow_uploads' => 'Tillad nye filoverførsler.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Føj tekst til begyndelsen (venstre side) af skyderen.',
'range.config.step' => 'Minimumsstørrelsen mellem værdierne.',
'relationship.config.mode' => 'Vælg din foretrukne UI-stil.',
'select.config.cast_booleans' => 'Valgmuligheder med værdierne sandt og falsk gemmes som booleanske.',
'select.config.clearable' => 'Aktiver for at tillade fravælgelse af din indstilling.',
'select.config.multiple' => 'Tillad flere valg.',
'select.config.options' => 'Indstil tasterne og deres valgfri etiketter.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/de-CH/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Standardwert festlegen.',
'any.config.cast_booleans' => 'Optionen mit den Werten *true* und *false* als Booleans speichern.',
'array.config.keys' => 'Arrayschlüssel (Variablen) und optionale Beschriftungen festlegen.',
'array.config.mode' => 'Der dynamische Modus gibt der Benutzer*in die Kontrolle über die Daten, während der geschlossene Modus dies nicht tut.',
'assets.config.allow_uploads' => 'Das Hochladen neuer Dateien zulassen.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Text auf der linke Seite des Schiebereglers hinzufügen.',
'range.config.step' => 'Mindestgrösse zwischen den Werten.',
'relationship.config.mode' => 'Bevorzugten UI Stil auswählen.',
'select.config.cast_booleans' => 'Optionen mit den Werten *true* und *false* als Booleans speichern.',
'select.config.clearable' => 'Option zum Abwählen der Auswahl aktivieren.',
'select.config.multiple' => 'Mehrfachauswahl zulassen.',
'select.config.options' => 'Arrayschlüssel und deren optionale Beschriftungen festlegen.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/de/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Standardwert festlegen.',
'any.config.cast_booleans' => 'Optionen mit den Werten *true* und *false* als Booleans speichern.',
'array.config.keys' => 'Arrayschlüssel (Variablen) und optionale Beschriftungen festlegen.',
'array.config.mode' => 'Der dynamische Modus gibt der Benutzer*in die Kontrolle über die Daten, während der geschlossene Modus dies nicht tut.',
'assets.config.allow_uploads' => 'Das Hochladen neuer Dateien zulassen.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Text auf der linke Seite des Schiebereglers hinzufügen.',
'range.config.step' => 'Mindestgröße zwischen den Werten.',
'relationship.config.mode' => 'Bevorzugten UI Stil auswählen.',
'select.config.cast_booleans' => 'Optionen mit den Werten *true* und *false* als Booleans speichern.',
'select.config.clearable' => 'Option zum Abwählen der Auswahl aktivieren.',
'select.config.multiple' => 'Mehrfachauswahl zulassen.',
'select.config.options' => 'Arrayschlüssel und deren optionale Beschriftungen festlegen.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Set the default value.',
'any.config.cast_booleans' => 'Options with values of true and false will be saved as booleans.',
'array.config.keys' => 'Set the array keys (variables) and optional labels.',
'array.config.mode' => 'Dynamic mode gives the user control of the data while keyed mode does not.',
'assets.config.allow_uploads' => 'Allow new file uploads.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Add text to the beginning (left-side) of the slider.',
'range.config.step' => 'The minimum size between values.',
'relationship.config.mode' => 'Choose your preferred UI style.',
'select.config.cast_booleans' => 'Options with values of true and false will be saved as booleans.',
'select.config.clearable' => 'Enable to allow deselecting your option.',
'select.config.multiple' => 'Allow multiple selections.',
'select.config.options' => 'Set the keys and their optional labels.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/es/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Establezca el valor predeterminado.',
'any.config.cast_booleans' => 'Las opciones con valores de verdadero y falso se guardarán como valores booleanos.',
'array.config.keys' => 'Establezca las claves de matriz (variables) y las etiquetas opcionales.',
'array.config.mode' => 'El modo dinámico le da al usuario el control de los datos mientras que el modo con clave no lo hace.',
'assets.config.allow_uploads' => 'Permitir nuevas cargas de archivos.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Agregue texto al principio (lado izquierdo) del control deslizante.',
'range.config.step' => 'El tamaño mínimo entre valores.',
'relationship.config.mode' => 'Elija su estilo de interfaz de usuario preferido.',
'select.config.cast_booleans' => 'Las opciones con valores de verdadero y falso se guardarán como valores booleanos.',
'select.config.clearable' => 'Habilite para permitir anular la selección de su opción.',
'select.config.multiple' => 'Permitir múltiples selecciones.',
'select.config.options' => 'Establecer las teclas y sus etiquetas opcionales.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fr/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Définissez la valeur par défaut.',
'any.config.cast_booleans' => 'Les options avec des valeurs true (vrai) et false (faux) seront enregistrées en tant que booléens.',
'array.config.keys' => 'Définissez les clés du tableau (les variables) et leurs étiquettes facultatives.',
'array.config.mode' => 'Le mode dynamique donne à l’utilisateur le contrôle des données, contrairement au mode à clé.',
'assets.config.allow_uploads' => 'Autorisez le téléversement de nouveaux fichiers.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Ajoutez du texte au début (côté gauche) du curseur.',
'range.config.step' => 'La taille minimale entre les valeurs.',
'relationship.config.mode' => 'Choisissez votre style d’interface utilisateur préféré.',
'select.config.cast_booleans' => 'Les options avec des valeurs true (vrai) et false (faux) seront enregistrées en tant que booléens.',
'select.config.clearable' => 'Activez pour permettre de désélectionner votre option.',
'select.config.multiple' => 'Autorisez des sélections multiples.',
'select.config.options' => 'Définissez les clés et leurs étiquettes facultatives.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/it/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Imposta il valore predefinito.',
'any.config.cast_booleans' => 'Le opzioni con valori "true" e "false" verranno salvate come booleani.',
'array.config.keys' => 'Imposta le chiavi dell\'array (variabili) e le etichette opzionali.',
'array.config.mode' => 'La modalità dinamica consente all\'utente di controllare i dati a differenza della modalità fissa.',
'assets.config.allow_uploads' => 'Consenti nuovi caricamenti di file.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Aggiungi testo all\'inizio (lato sinistro) dello slider.',
'range.config.step' => 'Lo step tra i valori.',
'relationship.config.mode' => 'Scegli il tuo stile di layout preferito.',
'select.config.cast_booleans' => 'Le opzioni con valori "true" e "false" verranno salvate come booleani.',
'select.config.clearable' => 'Abilita per consentire la deselezione dell\'opzione.',
'select.config.multiple' => 'Consenti la selezione multipla delle opzioni.',
'select.config.options' => 'Imposta le chiavi e le loro etichette opzionali.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/nl/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Stel de standaardwaarde in',
'any.config.cast_booleans' => 'Opties met de waarde true en false worden ogeslagen als booleans.',
'array.config.keys' => 'Stel de array keys (variabelen) en optionele labels in.',
'array.config.mode' => 'Dynamische modus geeft de gebruiker controle over de data terwijl keyed modus dat niet doet.',
'assets.config.allow_uploads' => 'Nieuwe file-uploads toestaan',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Voeg tekst toe aan het begin (linkerkant) van de slider.',
'range.config.step' => 'De minimumafstand tussen waardes.',
'relationship.config.mode' => 'Kies de UI-stijl die je voorkeur heeft.',
'select.config.cast_booleans' => 'Opties met de waarde true en false worden ogeslagen als booleans.',
'select.config.clearable' => 'Schakel in om het deselecteren van een optie toe te staan.',
'select.config.multiple' => 'Sta meerdere selecties toe',
'select.config.options' => 'Stel de keys hun optionele labels in.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/pt/fieldtypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return [
'any.config.default' => 'Definir o valor padrão',
'any.config.cast_booleans' => 'Opções com valores de verdadeiro e falso serão salvas como booleans.',
'array.config.keys' => 'O modo dinâmico dá ao utilizador o controlo dos dados enquanto que o modo com chave não o faz.',
'array.config.mode' => 'Defina as chaves da matriz (variáveis) e as etiquetas opcionais.',
'assets.config.allow_uploads' => 'Permitir o carregamento de novos ficheiros.',
Expand Down Expand Up @@ -66,7 +67,6 @@
'range.config.prepend' => 'Adicionar texto ao início (lado esquerdo) da barra deslizante.',
'range.config.step' => 'A dimensão mínima entre os valores.',
'relationship.config.mode' => 'Escolha o seu estilo de interface do usuário preferido.',
'select.config.cast_booleans' => 'Opções com valores de verdadeiro e falso serão salvas como booleans.',
'select.config.clearable' => 'Permitir a desmarcação da sua opção.',
'select.config.multiple' => 'Permitir selecções múltiplas.',
'select.config.options' => 'Defina as chaves e as suas etiquetas opcionais.',
Expand Down
33 changes: 33 additions & 0 deletions src/Fieldtypes/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ protected function configFieldItems(): array
'type' => 'toggle',
'width' => 50,
],
'cast_booleans' => [
'display' => __('Cast Booleans'),
'instructions' => __('statamic::fieldtypes.any.config.cast_booleans'),
'type' => 'toggle',
'default' => false,
'width' => 50,
],
];
}

Expand All @@ -31,4 +38,30 @@ public function augment($value)

return new LabeledValue($value, $label);
}

public function preProcess($value)
{
if ($this->config('cast_booleans')) {
if ($value === true) {
return 'true';
} elseif ($value === false) {
return 'false';
}
}

return $value;
}

public function process($value)
{
if ($this->config('cast_booleans')) {
if ($value === 'true') {
return true;
} elseif ($value === 'false') {
return false;
}
}

return $value;
}
}
2 changes: 1 addition & 1 deletion src/Fieldtypes/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function configFieldItems(): array
],
'cast_booleans' => [
'display' => __('Cast Booleans'),
'instructions' => __('statamic::fieldtypes.select.config.cast_booleans'),
'instructions' => __('statamic::fieldtypes.any.config.cast_booleans'),
'type' => 'toggle',
'default' => false,
'width' => 50,
Expand Down