Skip to content

Commit

Permalink
Merge branch '1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbieniek committed Apr 15, 2021
2 parents 6d49559 + d363d26 commit d31b7cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib/Form/Type/FieldType/DateFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Form Type representing ezdate field type.
*/
class DateFieldType extends AbstractType
{
private const EDIT_VIEWS = ['ezplatform.content.draft.edit', 'ezplatform.content.translate'];

/** @var \Symfony\Component\HttpFoundation\RequestStack */
private $requestStack;

public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

public function getName()
{
return $this->getBlockPrefix();
Expand All @@ -38,4 +51,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->addModelTransformer(new DateValueTransformer());
}

public function buildView(FormView $view, FormInterface $form, array $options)
{
$request = $this->requestStack->getCurrentRequest();
$view->vars['isEditView'] = \in_array($request->attributes->get('_route'), self::EDIT_VIEWS);
}
}

0 comments on commit d31b7cc

Please sign in to comment.