Symfony2 встроенная форма, класс не существует — переводы A2lix

Я использую две сущности в одной форме, ContentType в EstablishmentType. Если я использую только «классический» тип поля, я не получаю ошибок. Но когда я добавляю поле «translations» с «a2lix_translations_gedmo» в качестве типа в ContentType, оно возвращает ReflectionException «Класс не существует».

Переводы с A2lix отлично работают в других организациях.

Как кто-нибудь задумался?

Код ниже:

EstablishmentType.php

namespace Demo\FoundationBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class EstablishmentType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('content', new ContentType(),array(
'data_class'=>null
))
->add('translations', 'a2lix_translations_gedmo',array(
'translatable_class' => "Demo\FoundationBundle\Entity\Establishment",
))
->add('category','entity',array(
'class'=>'Demo\FoundationBundle\Entity\Category',
"required"=>true,
'label'=>'Categorie'
))
->add('file','file')
->add('participationLevel','number',array(
'label'=>'Taux de participation'
))
;
}

ContentType.php
пространство имен Демо \ FoundationBundle \ Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ContentType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type','choice',
array(
'choices'=>array(
'text'=>'Texte',
'highlight'=>'Mise en avant'
),
'required'=>false
))
->add('translations', 'a2lix_translations_gedmo',array(
'translatable_class' => "Demo\FoundationBundle\Entity\Content",
))
->add('class','text',array(
'label'=>'Classe css',
'required'=>false
))
->add('column_nb','number',array(
'label'=>'Nombre de colonnes',
'required'=>false
))
;
}

Трассировки стека

ReflectionException: Class  does not exist
at n/a
in /var/www/html/Demo/app/cache/dev/classes.php line 6969

at ReflectionClass->__construct('')
in /var/www/html/Demo/app/cache/dev/classes.php line 6969

at Doctrine\Common\Persistence\AbstractManagerRegistry->getManagerForClass(null)
in /var/www/html/Demo/vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/TranslationForm/GedmoTranslationForm.php line 45

at A2lix\TranslationFormBundle\TranslationForm\GedmoTranslationForm->getGedmoConfig(null)
in /var/www/html/Demo/vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/TranslationForm/GedmoTranslationForm.php line 67

at A2lix\TranslationFormBundle\TranslationForm\GedmoTranslationForm->getTranslatableFields(null)
in /var/www/html/Demo/vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/TranslationForm/TranslationForm.php line 48

at A2lix\TranslationFormBundle\TranslationForm\TranslationForm->getChildrenOptions(null, array('block_name' => null, 'disabled' => false, 'label' => null, 'label_format' => null, 'translation_domain' => null, 'auto_initialize' => true, 'trim' => true, 'required' => true, 'read_only' => false, 'max_length' => null, 'pattern' => null, 'property_path' => null, 'mapped' => true, 'by_reference' => true, 'virtual' => null, 'compound' => true, 'method' => 'POST', 'action' => '', 'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.', 'error_mapping' => array(), 'cascade_validation' => false, 'invalid_message' => 'This value is not valid.', 'invalid_message_parameters' => array(), 'allow_extra_fields' => false, 'extra_fields_message' => 'This form should not contain extra fields.', 'csrf_protection' => true, 'csrf_field_name' => '_token', 'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.', 'csrf_provider' => object(CsrfTokenManager), 'intention' => null, 'locales' => array('fr', 'de', 'en'), 'fields' => array(), 'attr' => array(), 'data_class' => null, 'empty_data' => object(Closure), 'error_bubbling' => true, 'label_attr' => array(), 'inherit_data' => false, 'validation_groups' => null, 'constraints' => array(), 'csrf_token_manager' => object(CsrfTokenManager), 'csrf_token_id' => null, 'translatable_class' => 'Demo\FoundationBundle\Entity\Content'))
in /var/www/html/Demo/vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/Form/EventListener/GedmoTranslationsListener.php line 45

at A2lix\TranslationFormBundle\Form\EventListener\GedmoTranslationsListener->preSetData(object(FormEvent), 'form.pre_set_data', object(EventDispatcher))
in  line

at call_user_func(array(object(GedmoTranslationsListener), 'preSetData'), object(FormEvent), 'form.pre_set_data', object(EventDispatcher))
in /var/www/html/Demo/app/cache/dev/classes.php line 1834

at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(array(object(GedmoTranslationsListener), 'preSetData')), 'form.pre_set_data', object(FormEvent))
in /var/www/html/Demo/app/cache/dev/classes.php line 1763

at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('form.pre_set_data', object(FormEvent))
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php line 43

at Symfony\Component\EventDispatcher\ImmutableEventDispatcher->dispatch('form.pre_set_data', object(FormEvent))
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 342

at Symfony\Component\Form\Form->setData(null)
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57

at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(ArrayCollection), object(RecursiveIteratorIterator))
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 396

at Symfony\Component\Form\Form->setData(object(ArrayCollection))
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php line 57

at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(Establishment), object(RecursiveIteratorIterator))
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 396

at Symfony\Component\Form\Form->setData(object(Establishment))
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 488

at Symfony\Component\Form\Form->initialize()
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/FormBuilder.php line 226

at Symfony\Component\Form\FormBuilder->getForm()
in /var/www/html/Demo/vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php line 39

at Symfony\Component\Form\FormFactory->create(object(EstablishmentType), object(Establishment))
in /var/www/html/Demo/src/Demo/AdminBundle/Controller/Est/NewController.php line 17

at Demo\AdminBundle\Controller\Est\NewController->indexAction()
in  line

at call_user_func_array(array(object(NewController), 'indexAction'), array())
in /var/www/html/Demo/app/bootstrap.php.cache line 3109

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in /var/www/html/Demo/app/bootstrap.php.cache line 3071

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in /var/www/html/Demo/app/bootstrap.php.cache line 3222

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in /var/www/html/Demo/app/bootstrap.php.cache line 2444

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /var/www/html/Demo/web/app_dev.php line 28

1

Решение

Сам пакет прекрасно справится с классом перевода, если вы определили data_class в ContentType::configureOptions:

->add('translations', 'a2lix_translations_gedmo',array(
'translatable_class' => "Demo\FoundationBundle\Entity\Content",
))

может просто стать:

->add('translations', 'a2lix_translations')

… если вы добавите

public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);

$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\YourEntity'
));
}

Конфигурация перевода не обрабатывается через FormType, но должен обрабатываться через сущность.

0

Другие решения

Если вы используете текущую основную версию (2.0) пакета, a2lix_translations_gedmo больше не существует

Вы должны использовать

$builder->add('translations', 'a2lix_translatedEntity', array(
'class' => 'Demo\FoundationBundle\Entity\Content',
'translation_property' => 'text',
'multiple' => true,
));
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector