<commit_before><?php

/*
 * This file is part of the NekLandBaseAdminBundle package.
 *
 * (c) Nekland <http://nekland.fr/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nekland\Bundle\BaseAdminBundle\Crud\Form;

use Nekland\Bundle\BaseAdminBundle\Crud\Manager;
use Nekland\Bundle\BaseAdminBundle\Crud\Model\Resource;
use Nekland\Bundle\BaseAdminBundle\Form\DataTransformer\StringToFileTransformer;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Translation\Translator;

class Generator
{
    /**
     * @var Manager
     */
    private $manager;

    /**
     * @var \Symfony\Component\Form\FormFactory
     */
    private $formFactory;

    /**
     * @var \Symfony\Component\Translation\Translator
     */
    private $translator;

    /**
     * @var \Nekland\Bundle\BaseAdminBundle\Form\DataTransformer\StringToFileTransformer
     */
    private $fileTransformer;

    /**
     * @param Manager                 $manager
     * @param FormFactory             $factory
     * @param Translator              $translator
     * @param StringToFileTransformer $fileTransformer
     */
    public function __construct(Manager $manager, FormFactory $factory, Translator $translator, StringToFileTransformer $fileTransformer)
    {
        $this->manager         = $manager;
        $this->formFactory     = $factory;
        $this->translator      = $translator;
        $this->fileTransformer = $fileTransformer;
    }

    /**
     * Generate a form using an entity/object
     *
     * @param object $entity
     * @param \Nekland\Bundle\BaseAdminBundle\Crud\Model\Resource $resource
     * @param string $url
     * @param string $method
     *
     * @return \Symfony\Component\Form\Form
     */
    public function generate($entity, Resource $resource, $url, $method='POST')
    {
        $builder        = $this->formFactory->createBuilder('form', $entity);
        $properties     = $resource->getProperties();
        $defaultOptions = array('required' => false);

        foreach ($properties as $property) {
            if ($property->getEditable()) {
                $label = $property->getLabel();
                if (!empty($label)) {
                    $defaultOptions['label'] = $label;
                }

                $formType = $property->getFormType();

                if (empty($formType)) {
                    $builder->add($property->getName(), null, $defaultOptions);<commit_msg>Added label translations for form generator<commit_after><?php

/*
 * This file is part of the NekLandBaseAdminBundle package.
 *
 * (c) Nekland <http://nekland.fr/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Nekland\Bundle\BaseAdminBundle\Crud\Form;

use Nekland\Bundle\BaseAdminBundle\Crud\Manager;
use Nekland\Bundle\BaseAdminBundle\Crud\Model\Resource;
use Nekland\Bundle\BaseAdminBundle\Form\DataTransformer\StringToFileTransformer;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Translation\Translator;

class Generator
{
    /**
     * @var Manager
     */
    private $manager;

    /**
     * @var \Symfony\Component\Form\FormFactory
     */
    private $formFactory;

    /**
     * @var \Symfony\Component\Translation\Translator
     */
    private $translator;

    /**
     * @var \Nekland\Bundle\BaseAdminBundle\Form\DataTransformer\StringToFileTransformer
     */
    private $fileTransformer;

    /**
     * @param Manager                 $manager
     * @param FormFactory             $factory
     * @param Translator              $translator
     * @param StringToFileTransformer $fileTransformer
     */
    public function __construct(Manager $manager, FormFactory $factory, Translator $translator, StringToFileTransformer $fileTransformer)
    {
        $this->manager         = $manager;
        $this->formFactory     = $factory;
        $this->translator      = $translator;
        $this->fileTransformer = $fileTransformer;
    }

    /**
     * Generate a form using an entity/object
     *
     * @param object $entity
     * @param \Nekland\Bundle\BaseAdminBundle\Crud\Model\Resource $resource
     * @param string $url
     * @param string $method
     *
     * @return \Symfony\Component\Form\Form
     */
    public function generate($entity, Resource $resource, $url, $method='POST')
    {
        $builder        = $this->formFactory->createBuilder('form', $entity);
        $properties     = $resource->getProperties();
        $defaultOptions = array('required' => false);

        foreach ($properties as $property) {
            if ($property->getEditable()) {
                $label = $property->getLabel();
                if (!empty($label)) {
                    $defaultOptions['label'] = $this->translator->trans($label);
                }

                $formType = $property->getFormType();

                if (empty($formType)) {
                    $builder->add($property->getName(), null, $defaultOptions);
{'fraction_non_alphanumeric': 0.11980392156862744, 'fraction_numerical': 0.0, 'mean_word_length': 2.4512855209742894, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, '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': '3270917', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1392, 'n_words': 294}