Архив

Архив раздела ‘Symfony’

sonata_type_boolean значения true/false

23 июля 2015 Comments off

sonata_type_boolean по умолчанию использует «1» для true, «2» для false. Для того чтобы было 1/0 нужно установить опцию transform: true.
В большом проекте каждый раз указывать данную опцию не удобно, по этому можно сделать override данного типа:


$ app/console generate:bundle

Bundle namespace: Override/Sonata/CoreBundle
Bundle name [OverrideSonataCoreBundle]:
Target directory [../src]:
Configuration format (yml, xml, php, or annotation): yml
Do you want to generate the whole directory structure [no]?
Generating the bundle code: OK
Checking that the bundle is autoloaded: OK
Confirm automatic update of your Kernel [yes]? yes
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]? no
Importing the bundle routing resource: OK

Воссоздадим структуру создав структуру каталогов:
src/Override/Sonata/CoreBundle/Form/Type

И сам класс:

< ?php namespace Override\Sonata\CoreBundle\Form\Type; use Symfony\Component\OptionsResolver\OptionsResolver; class BooleanType extends \Sonata\CoreBundle\Form\Type\BooleanType{ /** * {@inheritDoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array(
'catalogue' => 'SonataCoreBundle',
'choices' => array(
self::TYPE_YES => 'label_type_yes',
self::TYPE_NO => 'label_type_no',
),
'transform' => true,
));
}
}

Отличие от родительского класса: ‘transform’ => true

Объявим в сервисах:

src/Override/Sonata/CoreBundle/Resources/config $ cat services.yml
services:
override.sonata.core.form.type.boolean:
class: Override\Sonata\CoreBundle\Form\Type\BooleanType
tags:
- { name: "form.type", alias: "sonata_type_boolean" }

JMSTranslationBundle + Sonata Admin

17 июля 2015 Comments off

1. Добавляем в composer.json


"jms/di-extra-bundle": "dev-master",
"jms/translation-bundle": "dev-master"

2. config_dev.yml

jms_translation:
configs:
vendor_core:
dirs: [%kernel.root_dir%/../src/Vendor/CoreBundle]
output_dir: %kernel.root_dir%/../src/Vendor/CoreBundle/Resources/translations
excluded_dirs: ["Test"]
extractors: [sonata_admin]

3. routing_dev.yml

JMSTranslationBundle_ui:
resource: @JMSTranslationBundle/Controller/
type: annotation
prefix: /_trans

4. Генерация файла
app/console translation:extract en --config=vendor_core --output-format=xliff

5. Редактирование

Доступно по http://127.0.0.1/_trans

Categories: Symfony Tags: ,