Skip to content

Instantly share code, notes, and snippets.

@anyt
Last active May 17, 2018 16:06
Show Gist options
  • Save anyt/04c5ebd9576b58edf17f9ef0ab5591e1 to your computer and use it in GitHub Desktop.
Save anyt/04c5ebd9576b58edf17f9ef0ab5591e1 to your computer and use it in GitHub Desktop.
Translate Task Priority field
<?php
namespace AppBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AppBundle extends Bundle
{
}
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
class AppExtension extends Extension
{
const ALIAS = 'app';
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
/**
* {@inheritDoc}
*/
public function getAlias()
{
return self::ALIAS;
}
}
bundles:
- { name: AppBundle\AppBundle, priority: 1000 }
Normal: New Normal
services:
task_type.form_type_extension:
class: AppBundle\Form\Extension\TaskTypeTypeExtension
tags:
- { name: form.type_extension, extended_type: Oro\Bundle\TaskBundle\Form\Type\TaskType }
<?php
// Form\Extension
namespace AppBundle\Form\Extension;
use Oro\Bundle\FormBundle\Utils\FormUtils;
use Oro\Bundle\TaskBundle\Form\Type\TaskType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class TaskTypeTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) {
$form = $event->getForm();
FormUtils::replaceField($form, 'taskPriority', ['translatable_options'=> true]);
}
);
}
public function getExtendedType()
{
return TaskType::class;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment