Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 635 Bytes

custom_prefix.md

File metadata and controls

21 lines (17 loc) · 635 Bytes

Custom prefix

If you want to provide custom prefix to options you can set levelPrefix option to callback that will be invoked for each option and it should return label.

use Yavin\Symfony\Form\Type\TreeType;

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('category', TreeType::class, [
        'class' => Category::class, // tree class
        'levelPrefix' => function ($label, $level, $data) {
            //$label - original label
            //$level - tree level
            //$data - entity instance

            return 'your custom prefix';
        },
    ]);
}