|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
| 4 | + * |
| 5 | + * Copyright (C) 2019 - 2026 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 | + |
| 24 | +namespace App\Form\InfoProviderSystem; |
| 25 | + |
| 26 | +use App\Services\InfoProviderSystem\ProviderRegistry; |
| 27 | +use Symfony\Component\Form\AbstractType; |
| 28 | +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
| 29 | +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
| 30 | +use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
| 31 | +use Symfony\Component\Form\Extension\Core\Type\UrlType; |
| 32 | +use Symfony\Component\Form\FormBuilderInterface; |
| 33 | + |
| 34 | +class FromURLFormType extends AbstractType |
| 35 | +{ |
| 36 | + public function __construct(private readonly ProviderRegistry $providerRegistry) |
| 37 | + { |
| 38 | + |
| 39 | + } |
| 40 | + |
| 41 | + public function buildForm(FormBuilderInterface $builder, array $options): void |
| 42 | + { |
| 43 | + $builder->add('url', UrlType::class, [ |
| 44 | + 'label' => 'info_providers.from_url.url.label', |
| 45 | + 'required' => true, |
| 46 | + ]); |
| 47 | + |
| 48 | + |
| 49 | + $builder->add('method', ChoiceType::class, [ |
| 50 | + 'expanded' => true, |
| 51 | + 'data' => 'generic_web', //Default value |
| 52 | + 'label' => 'info_providers.from_url.method', |
| 53 | + 'choices' => [ |
| 54 | + 'info_providers.from_url.method.generic_web' => 'generic_web', |
| 55 | + 'info_providers.from_url.method.ai_web' => 'ai_web', |
| 56 | + ], |
| 57 | + 'choice_attr' => function ($choice, $key, $value) { |
| 58 | + //Disable all providers that are not active |
| 59 | + $provider = $this->providerRegistry->getProviderByKey($value); |
| 60 | + if (!$provider->isActive()) { |
| 61 | + return ['disabled' => 'disabled']; |
| 62 | + } |
| 63 | + |
| 64 | + return []; |
| 65 | + }, |
| 66 | + |
| 67 | + //Render the choices as inline radio buttons |
| 68 | + 'label_attr' => [ |
| 69 | + 'class' => 'radio-inline', |
| 70 | + ], |
| 71 | + ]); |
| 72 | + |
| 73 | + $builder->add('no_cache', CheckboxType::class, [ |
| 74 | + 'label' => 'info_providers.from_url.no_cache', |
| 75 | + 'required' => false, |
| 76 | + ]); |
| 77 | + |
| 78 | + $builder->add('submit', SubmitType::class, [ |
| 79 | + 'label' => 'info_providers.search.submit', |
| 80 | + ]); |
| 81 | + } |
| 82 | +} |
0 commit comments