<commit_before><?php

namespace Ojs\AdminBundle\Form\Type;

use Doctrine\ORM\EntityRepository;
use Ojs\JournalBundle\Entity\PublisherRepository;
use OkulBilisim\LocationBundle\Form\EventListener\AddCountryFieldSubscriber;
use OkulBilisim\LocationBundle\Form\EventListener\AddProvinceFieldSubscriber;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PublisherType extends AbstractType
{
    private $selfId;

    /**
     * PublisherType constructor.
     * @param $selfId
     */
    public function __construct($selfId = null)
    {
        $this->selfId = $selfId;
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $selfId = $this->selfId;
        $publisherId = null;
        if(isset($options['data'])){
            $publisherId = $options['data']->getId() ? $options['data']->getId() : null;
        }
        $builder
            ->add(
                'name',
                'text',
                [
                    'label' => 'name',
                    'required' => true,
                    'attr' => [
                        'class' => "validate[required]",
                    ],
                ]
            )
            ->add('translations', 'a2lix_translations')
            ->add(
                'slug',
                'text',
                [
                    'label' => 'publisher.slug',
                    'attr' => [
                        'class' => "validate[required]",
                    ],
                ]
            )
            ->add(
                'publisherType',
                'entity',
                [
                    'label' => 'publishertype',
                    'class' => 'Ojs\JournalBundle\Entity\PublisherTypes',
                    'attr' => [
                        'class' => "validate[required]",
                    ],
                ]
            )
            ->add(
                'parent',
                'entity',
                [
                    'label' => 'parent',
                    'class' => 'Ojs\JournalBundle\Entity\Publisher',
                    'attr' => [
                        'class' => "select2-element",
                    ],
                    'placeholder' => 'none',
                    'empty_data'  => null,
                    'query_builder' => function (PublisherRepository $repository) use ($selfId) {
                        $query = $repository->createQueryBuilder('publisher');
                        if ($selfId != null) {
                            return $query
                                ->andWhere('publisher.id != :selfId')
                                ->setParameter('selfId', $selfId);
                        }
                        return $query;
                    }
                ]
            )
            ->add(
                'theme',
                'entity',
                array(
                    'label' => 'theme',
                    'class' => 'Ojs\JournalBundle\Entity\PublisherTheme',
                    'property' => 'title',<commit_msg>admin publisher create process parent can be null fixes #1165<commit_after><?php

namespace Ojs\AdminBundle\Form\Type;

use Doctrine\ORM\EntityRepository;
use Ojs\JournalBundle\Entity\PublisherRepository;
use OkulBilisim\LocationBundle\Form\EventListener\AddCountryFieldSubscriber;
use OkulBilisim\LocationBundle\Form\EventListener\AddProvinceFieldSubscriber;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PublisherType extends AbstractType
{
    private $selfId;

    /**
     * PublisherType constructor.
     * @param $selfId
     */
    public function __construct($selfId = null)
    {
        $this->selfId = $selfId;
    }

    /**
     * @param FormBuilderInterface $builder
     * @param array                $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $selfId = $this->selfId;
        $publisherId = null;
        if(isset($options['data'])){
            $publisherId = $options['data']->getId() ? $options['data']->getId() : null;
        }
        $builder
            ->add(
                'name',
                'text',
                [
                    'label' => 'name',
                    'required' => true,
                    'attr' => [
                        'class' => "validate[required]",
                    ],
                ]
            )
            ->add('translations', 'a2lix_translations')
            ->add(
                'slug',
                'text',
                [
                    'label' => 'publisher.slug',
                    'attr' => [
                        'class' => "validate[required]",
                    ],
                ]
            )
            ->add(
                'publisherType',
                'entity',
                [
                    'label' => 'publishertype',
                    'class' => 'Ojs\JournalBundle\Entity\PublisherTypes',
                    'attr' => [
                        'class' => "validate[required]",
                    ],
                ]
            )
            ->add(
                'parent',
                'entity',
                [
                    'label' => 'parent',
                    'required' => false,
                    'class' => 'Ojs\JournalBundle\Entity\Publisher',
                    'attr' => [
                        'class' => "select2-element",
                    ],
                    'placeholder' => 'none',
                    'empty_data'  => null,
                    'query_builder' => function (PublisherRepository $repository) use ($selfId) {
                        $query = $repository->createQueryBuilder('publisher');
                        if ($selfId != null) {
                            return $query
                                ->andWhere('publisher.id != :selfId')
                                ->setParameter('selfId', $selfId);
                        }
                        return $query;
                    }
                ]
            )
            ->add(
                'theme',
                'entity',
                array(
                    'label' => 'theme',
                    'class' => 'Ojs\JournalBundle\Entity\PublisherTheme',
                    'property' => 'title',
{'fraction_non_alphanumeric': 0.12036897021019205, 'fraction_numerical': 0.0012097383940722819, 'mean_word_length': 1.123274478330658, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808093', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1553, 'n_words': 266}