Loading app/Helpers/form_helper.phpdeleted 100644 → 0 +0 −81 Original line number Diff line number Diff line <?php declare(strict_types=1); /** * @copyright 2020 Podlibre * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @link https://castopod.org/ */ //-------------------------------------------------------------------- if (! function_exists('form_dropdown')) { /** * Drop-down Menu (based on html select tag) * * @param array<string, mixed> $options * @param array<string|int> $selected * @param array<string, mixed> $customExtra */ function form_dropdown( string $name = '', array $options = [], array $selected = [], array $customExtra = [] ): string { $defaultExtra = [ 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($defaultExtra, $customExtra); $defaults = [ 'name' => $name, ]; // standardize selected as strings, like the option keys will be. foreach ($selected as $key => $item) { $selected[$key] = $item; } $placeholderOption = ''; if (isset($extra['placeholder'])) { $placeholderOption = '<option value="" disabled="disabled" hidden="hidden"' . (in_array( '', $selected, true ) ? ' selected="selected"' : '') . '>' . $extra['placeholder'] . '</option>'; unset($extra['placeholder']); } $extra = stringify_attributes($extra); $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : ''; $form = '<select ' . rtrim(parse_form_attributes($name, $defaults)) . $extra . $multiple . ">\n"; $form .= $placeholderOption; foreach ($options as $key => $val) { if (is_array($val)) { if ($val === []) { continue; } $form .= '<optgroup label="' . $key . "\">\n"; foreach ($val as $optgroupKey => $optgroupVal) { $sel = in_array($optgroupKey, $selected, true) ? ' selected="selected"' : ''; $form .= '<option value="' . htmlspecialchars($optgroupKey) . '"' . $sel . '>' . $optgroupVal . "</option>\n"; } $form .= "</optgroup>\n"; } else { /** @noRector RecastingRemovalRector */ $form .= '<option value="' . htmlspecialchars((string) $key) . '"' . (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>' . $val . "</option>\n"; } } return $form . "</select>\n"; } } app/Views/Components/Forms/Checkbox.php +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ class Checkbox extends FormComponent 'name' => $this->name, 'class' => 'form-checkbox text-pine-500 border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 w-6 h-6', ], $this->value, 'yes', old($this->name) ? old($this->name) === $this->value : $this->isChecked, ); Loading app/Views/Components/Forms/Input.php +1 −10 Original line number Diff line number Diff line Loading @@ -10,16 +10,7 @@ class Input extends FormComponent public function render(): string { $class = 'px-3 py-2 bg-white rounded-lg border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class; if (session()->has('errors')) { $error = session('errors')[$this->name]; if ($error) { $class .= ' border-red'; } } else { $class .= ' border-black focus:border-black'; } $class = 'px-3 py-2 bg-white border-black rounded-lg focus:border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class; $this->attributes['class'] = $class; Loading app/Views/Components/Forms/MultiSelect.php +5 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,11 @@ class MultiSelect extends FormComponent $defaultAttributes = [ 'data-class' => $this->attributes['class'], 'multiple' => 'multiple', 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($defaultAttributes, $this->attributes); Loading app/Views/Components/Forms/Select.php +5 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,11 @@ class Select extends FormComponent $defaultAttributes = [ 'class' => 'focus:border-black focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 border-3 rounded-lg border-black ' . $this->class, 'data-class' => $this->class, 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($this->attributes, $defaultAttributes); Loading Loading
app/Helpers/form_helper.phpdeleted 100644 → 0 +0 −81 Original line number Diff line number Diff line <?php declare(strict_types=1); /** * @copyright 2020 Podlibre * @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3 * @link https://castopod.org/ */ //-------------------------------------------------------------------- if (! function_exists('form_dropdown')) { /** * Drop-down Menu (based on html select tag) * * @param array<string, mixed> $options * @param array<string|int> $selected * @param array<string, mixed> $customExtra */ function form_dropdown( string $name = '', array $options = [], array $selected = [], array $customExtra = [] ): string { $defaultExtra = [ 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($defaultExtra, $customExtra); $defaults = [ 'name' => $name, ]; // standardize selected as strings, like the option keys will be. foreach ($selected as $key => $item) { $selected[$key] = $item; } $placeholderOption = ''; if (isset($extra['placeholder'])) { $placeholderOption = '<option value="" disabled="disabled" hidden="hidden"' . (in_array( '', $selected, true ) ? ' selected="selected"' : '') . '>' . $extra['placeholder'] . '</option>'; unset($extra['placeholder']); } $extra = stringify_attributes($extra); $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : ''; $form = '<select ' . rtrim(parse_form_attributes($name, $defaults)) . $extra . $multiple . ">\n"; $form .= $placeholderOption; foreach ($options as $key => $val) { if (is_array($val)) { if ($val === []) { continue; } $form .= '<optgroup label="' . $key . "\">\n"; foreach ($val as $optgroupKey => $optgroupVal) { $sel = in_array($optgroupKey, $selected, true) ? ' selected="selected"' : ''; $form .= '<option value="' . htmlspecialchars($optgroupKey) . '"' . $sel . '>' . $optgroupVal . "</option>\n"; } $form .= "</optgroup>\n"; } else { /** @noRector RecastingRemovalRector */ $form .= '<option value="' . htmlspecialchars((string) $key) . '"' . (in_array($key, $selected, true) ? ' selected="selected"' : '') . '>' . $val . "</option>\n"; } } return $form . "</select>\n"; } }
app/Views/Components/Forms/Checkbox.php +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ class Checkbox extends FormComponent 'name' => $this->name, 'class' => 'form-checkbox text-pine-500 border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 w-6 h-6', ], $this->value, 'yes', old($this->name) ? old($this->name) === $this->value : $this->isChecked, ); Loading
app/Views/Components/Forms/Input.php +1 −10 Original line number Diff line number Diff line Loading @@ -10,16 +10,7 @@ class Input extends FormComponent public function render(): string { $class = 'px-3 py-2 bg-white rounded-lg border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class; if (session()->has('errors')) { $error = session('errors')[$this->name]; if ($error) { $class .= ' border-red'; } } else { $class .= ' border-black focus:border-black'; } $class = 'px-3 py-2 bg-white border-black rounded-lg focus:border-black border-3 focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 ' . $this->class; $this->attributes['class'] = $class; Loading
app/Views/Components/Forms/MultiSelect.php +5 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,11 @@ class MultiSelect extends FormComponent $defaultAttributes = [ 'data-class' => $this->attributes['class'], 'multiple' => 'multiple', 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($defaultAttributes, $this->attributes); Loading
app/Views/Components/Forms/Select.php +5 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,11 @@ class Select extends FormComponent $defaultAttributes = [ 'class' => 'focus:border-black focus:ring-2 focus:ring-pine-500 focus:ring-offset-2 focus:ring-offset-pine-100 border-3 rounded-lg border-black ' . $this->class, 'data-class' => $this->class, 'data-select-text' => lang('Common.forms.multiSelect.selectText'), 'data-loading-text' => lang('Common.forms.multiSelect.loadingText'), 'data-no-results-text' => lang('Common.forms.multiSelect.noResultsText'), 'data-no-choices-text' => lang('Common.forms.multiSelect.noChoicesText'), 'data-max-item-text' => lang('Common.forms.multiSelect.maxItemText'), ]; $extra = array_merge($this->attributes, $defaultAttributes); Loading