refactor: move scope field to trait

[ci skip] as we know tests are failing
This commit is contained in:
Julien Fastré 2015-06-24 22:32:28 +02:00
parent 7cf41d9c9d
commit 8445e81d44
3 changed files with 54 additions and 8 deletions

View File

@ -21,12 +21,54 @@
namespace Chill\ReportBundle\Form;
use Chill\MainBundle\Form\Type\AbstractHasScopeType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Chill\MainBundle\Form\Type\AppendScopeChoiceTypeTrait;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\Common\Persistence\ObjectManager;
class ReportType extends AbstractHasScopeType
class ReportType extends AbstractType
{
use AppendScopeChoiceTypeTrait;
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
*
* @var \Doctrine\Common\Persistence\ObjectManager
*/
protected $om;
/**
*
* @var \Chill\MainBundle\Entity\User
*/
protected $user;
public function __construct(AuthorizationHelper $helper,
TokenStorageInterface $tokenStorage,
TranslatableStringHelper $translatableStringHelper,
ObjectManager $om)
{
$this->authorizationHelper = $helper;
$this->user = $tokenStorage->getToken()->getUser();
$this->translatableStringHelper = $translatableStringHelper;
$this->om = $om;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
@ -42,16 +84,17 @@ class ReportType extends AbstractHasScopeType
'group' => $options['cFGroup']))
;
$this->appendScopeChoices($builder, $options);
$this->appendScopeChoices($builder, $options['role'], $options['center'],
$this->user, $this->authorizationHelper,
$this->translatableStringHelper,
$this->om);
}
/**
* @param OptionsResolverInterface $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
{
$resolver->setDefaults(array(
'data_class' => 'Chill\ReportBundle\Entity\Report'
));
@ -63,6 +106,8 @@ class ReportType extends AbstractHasScopeType
$resolver->setAllowedTypes(array(
'cFGroup' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup',
));
$this->appendScopeChoicesOptions($resolver);
}
/**

View File

@ -33,6 +33,7 @@ services:
- "@chill.main.security.authorization.helper"
- "@security.token_storage"
- "@chill.main.helper.translatable_string"
- "@doctrine.orm.entity_manager"
tags:
- { name: form.type, alias: chill_reportbundle_report }

View File

@ -30,8 +30,8 @@
<dl>
<dt class="inline">{{ 'Person'|trans }}</dt>
<dd>{{ entity.person }}</dd>
<!-- <dt class="inline">{{ 'Scope'|trans }}</dt>
<dd>{{ entity.scope }}</dd> -->
<dt class="inline">{{ 'Scope'|trans }}</dt>
<dd><span class="scope">{{ entity.scope.name|localize_translatable_string }}</span></dd>
<dt class="inline">{{ 'Date'|trans }}</dt>
<dd>{{ entity.date|localizeddate('long', 'none') }}</dd>
<dt class="inline">{{ 'User'|trans }}</dt>