Jacek Kowalski
4 hours ago 6b9278a5d57091fce636dbb640b380cfb990db6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
 
namespace App\Form;
 
use App\Entity\Book;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
 
/**
 * @extends AbstractType<Book>
 */
class BookType extends AbstractType {
    public function buildForm(FormBuilderInterface $builder, array $options): void {
        $builder
            ->add('id', IntegerType::class, ['label' => 'book_id_header', 'disabled' => $options['lock_id']])
            ->add('title', TextType::class, ['label' => 'book_title_header'])
            ->add('author', TextType::class, ['label' => 'book_author_header'])
            ->add('language', TextType::class, ['label' => 'book_language_header', 'required' => false])
            ->add('edition', TextType::class, ['label' => 'book_edition_header', 'required' => false])
            ->add('publisher', TextType::class, ['label' => 'book_publisher_header', 'required' => false])
            ->add('publicationLoc', TextType::class, ['label' => 'book_publication_loc_header', 'required' => false])
            ->add('publicationYear', IntegerType::class, ['label' => 'book_publication_year_header', 'required' => false])
            ->add('isbn', TextType::class, ['label' => 'book_isbn_header', 'required' => false])
            ->add('issn', TextType::class, ['label' => 'book_issn_header', 'required' => false])
            ->add('placement', TextType::class, ['label' => 'book_placement_header', 'required' => false])
            ->add('save', SubmitType::class, ['label' => 'book_action_save']);
    }
 
    public function configureOptions(OptionsResolver $resolver): void {
        $resolver->setDefaults([
            'data_class' => Book::class,
            'lock_id' => false,
        ]);
        $resolver->setAllowedTypes('lock_id', 'bool');
    }
}