<commit_before><?php

namespace Enhavo\Bundle\ArticleBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Routing\RouterInterface;

class ArticleType extends AbstractType
{
    /**
     * @var string
     */
    protected $dataClass;

    /**
     * @var RouterInterface
     */
    protected $router;

    /**
     * @var string
     */
    protected $route;

    /**
     * @var bool
     */
    protected $dynamicRouting;

    public function __construct($dataClass, $dynamicRouting, $route, RouterInterface $router)
    {
        $this->route = $route;
        $this->dataClass = $dataClass;
        $this->router = $router;
        $this->dynamicRouting = $dynamicRouting;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $router = $this->router;
        $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($router) {
            $article = $event->getData();
            $form = $event->getForm();

            if (!empty($article) && $article->getId() && !empty($route)) {
                $url = $router->generate($this->route, array(
                    'id' => $article->getId(),
                    'slug' => $article->getSlug(),
                ), true);

                $form->add('link', 'text', array(
                    'mapped' => false,
                    'data' => $url,
                    'disabled' => true
                ));
            }
        });

        if($this->dynamicRouting) {
            $builder->add('route', 'enhavo_route');
        }

        $builder->add('title', 'text', array(
            'label' => 'form.label.title',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('meta_description', 'textarea', array(
            'label' => 'form.label.meta_description',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('page_title', 'text', array(
            'label' => 'article.form.label.page_title',
            'translation_domain' => 'EnhavoArticleBundle'
        ));

        $builder->add('slug', 'text', array(
            'label' => 'form.label.slug',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('public', 'enhavo_boolean', array(
            'label' => 'form.label.picture',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('social_media', 'enhavo_boolean', array(
                'label' => 'article.form.label.social_media',
                'translation_domain' => 'EnhavoArticleBundle'
        ));

        $builder->add('priority', 'choice', array(
            'label' => 'article.form.label.priority',
            'translation_domain' => 'EnhavoArticleBundle',
            'choices'   => array(
                '0.1' => '1',
                '0.2' => '2',
                '0.3' => '3',
                '0.4' => '4',
                '0.5' => '5',
                '0.6' => '6',
                '0.7' => '7',
                '0.8' => '8',<commit_msg>fix grid templates and some translations<commit_after><?php

namespace Enhavo\Bundle\ArticleBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Routing\RouterInterface;

class ArticleType extends AbstractType
{
    /**
     * @var string
     */
    protected $dataClass;

    /**
     * @var RouterInterface
     */
    protected $router;

    /**
     * @var string
     */
    protected $route;

    /**
     * @var bool
     */
    protected $dynamicRouting;

    public function __construct($dataClass, $dynamicRouting, $route, RouterInterface $router)
    {
        $this->route = $route;
        $this->dataClass = $dataClass;
        $this->router = $router;
        $this->dynamicRouting = $dynamicRouting;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $router = $this->router;
        $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($router) {
            $article = $event->getData();
            $form = $event->getForm();

            if (!empty($article) && $article->getId() && !empty($route)) {
                $url = $router->generate($this->route, array(
                    'id' => $article->getId(),
                    'slug' => $article->getSlug(),
                ), true);

                $form->add('link', 'text', array(
                    'mapped' => false,
                    'data' => $url,
                    'disabled' => true
                ));
            }
        });

        if($this->dynamicRouting) {
            $builder->add('route', 'enhavo_route');
        }

        $builder->add('title', 'text', array(
            'label' => 'form.label.title',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('meta_description', 'textarea', array(
            'label' => 'form.label.meta_description',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('page_title', 'text', array(
            'label' => 'article.form.label.page_title',
            'translation_domain' => 'EnhavoArticleBundle'
        ));

        $builder->add('slug', 'text', array(
            'label' => 'form.label.slug',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('public', 'enhavo_boolean', array(
            'label' => 'form.label.public',
            'translation_domain' => 'EnhavoAppBundle'
        ));

        $builder->add('social_media', 'enhavo_boolean', array(
                'label' => 'article.form.label.social_media',
                'translation_domain' => 'EnhavoArticleBundle'
        ));

        $builder->add('priority', 'choice', array(
            'label' => 'article.form.label.priority',
            'translation_domain' => 'EnhavoArticleBundle',
            'choices'   => array(
                '0.1' => '1',
                '0.2' => '2',
                '0.3' => '3',
                '0.4' => '4',
                '0.5' => '5',
                '0.6' => '6',
                '0.7' => '7',
                '0.8' => '8',
{'fraction_non_alphanumeric': 0.16062176165803108, 'fraction_numerical': 0.00731484303565986, 'mean_word_length': 1.8911894273127754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 105, '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': '3710561', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1881, 'n_words': 322}