|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
| 4 | + * |
| 5 | + * Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics) |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as published |
| 9 | + * by the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +declare(strict_types=1); |
| 22 | + |
| 23 | +namespace App\Form\Settings; |
| 24 | + |
| 25 | +use Symfony\Component\Form\AbstractType; |
| 26 | +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
| 27 | +use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
| 28 | +use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
| 29 | +use Symfony\Component\Form\FormBuilderInterface; |
| 30 | +use Symfony\Component\OptionsResolver\OptionsResolver; |
| 31 | + |
| 32 | +/** |
| 33 | + * Form type for editing the custom KiCad footprints and symbols lists. |
| 34 | + */ |
| 35 | +final class KicadListEditorType extends AbstractType |
| 36 | +{ |
| 37 | + public function buildForm(FormBuilderInterface $builder, array $options): void |
| 38 | + { |
| 39 | + $builder |
| 40 | + ->add('useCustomList', CheckboxType::class, [ |
| 41 | + 'label' => 'settings.misc.kicad_eda.use_custom_list', |
| 42 | + 'help' => 'settings.misc.kicad_eda.use_custom_list.help', |
| 43 | + 'required' => false, |
| 44 | + ]) |
| 45 | + ->add('customFootprints', TextareaType::class, [ |
| 46 | + 'label' => 'settings.misc.kicad_eda.editor.custom_footprints', |
| 47 | + 'help' => 'settings.misc.kicad_eda.editor.footprints.help', |
| 48 | + 'attr' => [ |
| 49 | + 'rows' => 16, |
| 50 | + 'spellcheck' => 'false', |
| 51 | + 'class' => 'font-monospace', |
| 52 | + ], |
| 53 | + ]) |
| 54 | + ->add('defaultFootprints', TextareaType::class, [ |
| 55 | + 'label' => 'settings.misc.kicad_eda.editor.default_footprints', |
| 56 | + 'help' => 'settings.misc.kicad_eda.editor.default_files_help', |
| 57 | + 'disabled' => true, |
| 58 | + 'mapped' => false, |
| 59 | + 'data' => $options['default_footprints'], |
| 60 | + 'attr' => [ |
| 61 | + 'rows' => 16, |
| 62 | + 'spellcheck' => 'false', |
| 63 | + 'class' => 'font-monospace', |
| 64 | + 'readonly' => 'readonly', |
| 65 | + ], |
| 66 | + ]) |
| 67 | + ->add('customSymbols', TextareaType::class, [ |
| 68 | + 'label' => 'settings.misc.kicad_eda.editor.custom_symbols', |
| 69 | + 'help' => 'settings.misc.kicad_eda.editor.symbols.help', |
| 70 | + 'attr' => [ |
| 71 | + 'rows' => 16, |
| 72 | + 'spellcheck' => 'false', |
| 73 | + 'class' => 'font-monospace', |
| 74 | + ], |
| 75 | + ]) |
| 76 | + ->add('defaultSymbols', TextareaType::class, [ |
| 77 | + 'label' => 'settings.misc.kicad_eda.editor.default_symbols', |
| 78 | + 'help' => 'settings.misc.kicad_eda.editor.default_files_help', |
| 79 | + 'disabled' => true, |
| 80 | + 'mapped' => false, |
| 81 | + 'data' => $options['default_symbols'], |
| 82 | + 'attr' => [ |
| 83 | + 'rows' => 16, |
| 84 | + 'spellcheck' => 'false', |
| 85 | + 'class' => 'font-monospace', |
| 86 | + 'readonly' => 'readonly', |
| 87 | + ], |
| 88 | + ]) |
| 89 | + ->add('save', SubmitType::class, [ |
| 90 | + 'label' => 'save', |
| 91 | + ]); |
| 92 | + } |
| 93 | + |
| 94 | + public function configureOptions(OptionsResolver $resolver): void |
| 95 | + { |
| 96 | + $resolver->setDefaults([ |
| 97 | + 'default_footprints' => '', |
| 98 | + 'default_symbols' => '', |
| 99 | + ]); |
| 100 | + $resolver->setAllowedTypes('default_footprints', 'string'); |
| 101 | + $resolver->setAllowedTypes('default_symbols', 'string'); |
| 102 | + } |
| 103 | +} |
0 commit comments