<commit_before><?php

namespace OpenOrchestra\BackofficeBundle\EventSubscriber;

use Doctrine\Common\Util\Inflector;
use OpenOrchestra\BackofficeBundle\StrategyManager\GenerateFormManager;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormFactoryInterface;

/**
 * Class BlockTypeSubscriber
 */
class BlockTypeSubscriber extends AbstractBlockContentTypeSubscriber
{
    protected $generateFormManager;
    protected $fixedParameters;
    protected $blockPosition;
    protected $formFactory;

    /**
     * @param GenerateFormManager  $generateFormManager
     * @param array                $fixedParameters
     * @param FormFactoryInterface $formFactory
     * @param int                  $blockPosition
     */
    public function __construct(GenerateFormManager $generateFormManager, $fixedParameters, FormFactoryInterface $formFactory, $blockPosition = 0)
    {
        $this->generateFormManager = $generateFormManager;
        $this->fixedParameters = $fixedParameters;
        $this->blockPosition = $blockPosition;
        $this->formFactory = $formFactory;
    }

    /**
     * @param FormEvent $event
     */
    public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        $label = $data->getLabel();
        if ('' == $label) {
            $data->setLabel($data->getComponent() . ' #' . ($this->blockPosition + 1));
        }

        $newForm = $this->formFactory->create($this->generateFormManager->createForm($data));

        foreach ($form->all() as $formChild) {
            $form->remove($formChild->getName());
            if($newForm->has($formChild->getName())){
                $formChild = $newForm->get($formChild->getName());
            }<commit_msg>add possibility to change common properties of blocks<commit_after><?php

namespace OpenOrchestra\BackofficeBundle\EventSubscriber;

use Doctrine\Common\Util\Inflector;
use OpenOrchestra\BackofficeBundle\StrategyManager\GenerateFormManager;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormFactoryInterface;

/**
 * Class BlockTypeSubscriber
 */
class BlockTypeSubscriber extends AbstractBlockContentTypeSubscriber
{
    protected $generateFormManager;
    protected $fixedParameters;
    protected $blockPosition;
    protected $formFactory;

    /**
     * @param GenerateFormManager  $generateFormManager
     * @param array                $fixedParameters
     * @param FormFactoryInterface $formFactory
     * @param int                  $blockPosition
     */
    public function __construct(GenerateFormManager $generateFormManager, $fixedParameters, FormFactoryInterface $formFactory, $blockPosition = 0)
    {
        $this->generateFormManager = $generateFormManager;
        $this->fixedParameters = $fixedParameters;
        $this->blockPosition = $blockPosition;
        $this->formFactory = $formFactory;
    }

    /**
     * @param FormEvent $event
     */
    public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        $label = $data->getLabel();
        if ('' == $label) {
            $data->setLabel($data->getComponent() . ' #' . ($this->blockPosition + 1));
        }

        $newForm = $this->formFactory->create($this->generateFormManager->createForm($data));

        foreach ($form->all() as $formChild) {
            $form->remove($formChild->getName());
            if($newForm->has($formChild->getName())){
                $formChild = $newForm->get($formChild->getName());
                $newForm->remove($formChild->getName());
            }
{'fraction_non_alphanumeric': 0.12392829306313329, 'fraction_numerical': 0.0010392309690828788, 'mean_word_length': 3.189336235038085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '7147092', 'n_tokens_mistral': 1024, 'n_tokens_neox': 1007, 'n_words': 180}