Skip to content

Commit

Permalink
Merge pull request #9 from kaloqndamqnov/master
Browse files Browse the repository at this point in the history
symfony 3.0 support
  • Loading branch information
Warxcell authored Apr 7, 2017
2 parents 3713be8 + a49663d commit 1e1a943
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 68 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"require": {
"sonata-project/admin-bundle": "~2.2 || ~3.0",
"sonata-project/doctrine-orm-admin-bundle": "~2.2 || ~3.0"
"sonata-project/doctrine-orm-admin-bundle": "~2.2 || ~3.0",
"symfony/framework-bundle": "~2.4|~3.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace ObjectBG\TranslationBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\DependencyInjection\Container;

class Language extends Admin
class Language extends AbstractAdmin
{

private $Container;
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/TokenTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ObjectBG\TranslationBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;

class TokenTranslation extends Admin
class TokenTranslation extends AbstractAdmin
{

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Admin/TranslationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace ObjectBG\TranslationBundle\Admin;

use Doctrine\ORM\EntityManager;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class TranslationToken extends Admin
class TranslationToken extends AbstractAdmin
{

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Form/EventListener/TranslationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ObjectBG\TranslationBundle\Form\EventListener;

use ObjectBG\TranslationBundle\Form\Type\TranslationsFieldsType;
use ObjectBG\TranslationBundle\TranslationService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
Expand Down Expand Up @@ -65,7 +66,7 @@ public function preSetData(FormEvent $event)
if (isset($fieldsOptions[$locale])) {
$form->add(
$locale,
'object_bg_translation_fields',
TranslationsFieldsType::class,
array(
'label' => $name,
'data_class' => $translationClass,
Expand Down
26 changes: 12 additions & 14 deletions src/Form/Type/TranslatedEntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace ObjectBG\TranslationBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;

/**
* Translated entity
Expand All @@ -14,19 +15,21 @@
*/
class TranslatedEntityType extends AbstractType
{

/**
* @var Request
*/
private $request;

public function setRequest(Request $request = null)
public function setRequest(RequestStack $request = null)
{
$this->request = $request;
$this->request = $request->getCurrentRequest();
}

/**
*
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
Expand All @@ -37,20 +40,15 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
throw new \Exception('Error while getting request');
}

return $options['translation_path'].'['.$this->request->getLocale(
).'].'.$options['translation_property'];
return $options['translation_path'] . '[' . $this->request->getLocale() . '].' . $options['translation_property'];
},
)
);
}

public function getParent()
{
return 'entity';
return EntityType::class;
}

public function getName()
{
return 'object_bg_translated_entity';
}
}
11 changes: 4 additions & 7 deletions src/Form/Type/TranslationsFieldsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

class TranslationsFieldsType extends AbstractType
{
Expand All @@ -26,9 +26,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)

/**
*
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
Expand All @@ -37,8 +37,5 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
);
}

public function getName()
{
return 'object_bg_translation_fields';
}

}
10 changes: 3 additions & 7 deletions src/Form/Type/TranslationsFormsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
*
Expand Down Expand Up @@ -80,9 +80,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)

/**
*
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
Expand All @@ -95,8 +95,4 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
);
}

public function getName()
{
return 'object_bg_translations_forms';
}
}
12 changes: 4 additions & 8 deletions src/Form/Type/TranslationsLocalesSelectorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ObjectBG\TranslationBundle\Form\Type;

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

class TranslationsLocalesSelectorType extends AbstractType
{
Expand All @@ -26,9 +26,9 @@ public function __construct()

/**
*
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
Expand All @@ -44,11 +44,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)

public function getParent()
{
return 'choice';
return \Symfony\Component\Form\Extension\Core\Type\ChoiceType::class;
}

public function getName()
{
return 'object_bg_locales_selector';
}
}
10 changes: 3 additions & 7 deletions src/Form/Type/TranslationsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TranslationsType extends AbstractType
{
Expand Down Expand Up @@ -53,9 +53,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)

/**
*
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
Expand All @@ -71,8 +71,4 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
);
}

public function getName()
{
return 'object_bg_translations';
}
}
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<service id="object_bg.translation.form.type.translatedEntity" class="ObjectBG\TranslationBundle\Form\Type\TranslatedEntityType">
<call method="setRequest">
<argument type="service" id="request" on-invalid="null" strict="false" />
<argument type="service" id="request_stack" on-invalid="null" strict="false" />
</call>
<tag name="form.type" alias="object_bg_translated_entity" />
</service>
Expand Down
24 changes: 8 additions & 16 deletions src/TranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ class TranslationService

/**
*
* @param \Symfony\Component\DependencyInjection\Container $Container
* @param \Symfony\Component\DependencyInjection\Container $container
* @param \Symfony\Component\Form\FormRegistry $formRegistry
* @param \Doctrine\Common\Persistence\ManagerRegistry $managerRegistry
* @param \Doctrine\Common\Annotations\Reader $Reader
*/
public function __construct(Container $Container)
public function __construct(Container $container)
{
$this->container = $Container;
$this->typeGuesser = $Container->get('form.registry')->getTypeGuesser();
$this->managerRegistry = $Container->get('doctrine');
$this->annotationReader = $Container->get('annotation_reader');
$this->translator = $Container->get('translator.default');
$this->request = $Container->get('request');
$this->container = $container;
$this->typeGuesser = $container->get('form.registry')->getTypeGuesser();
$this->managerRegistry = $container->get('doctrine');
$this->annotationReader = $container->get('annotation_reader');
$this->translator = $container->get('translator.default');
$this->request = $container->get('request_stack')->getCurrentRequest();
$this->propertyAccess = PropertyAccess::createPropertyAccessor();
}

Expand Down Expand Up @@ -349,14 +349,6 @@ public function guessMissingFieldOptions($guesser, $class, $property, $options)
$options['field_type'] = $typeGuess->getType();
}

if (!isset($options['pattern']) && ($patternGuess = $guesser->guessPattern($class, $property))) {
$options['pattern'] = $patternGuess->getValue();
}

if (!isset($options['max_length']) && ($maxLengthGuess = $guesser->guessMaxLength($class, $property))) {
$options['max_length'] = $maxLengthGuess->getValue();
}

return $options;
}
}

0 comments on commit 1e1a943

Please sign in to comment.