Search code examples
phpsymfonysymfony-formssonata-admin

sonata color the fields


I am trying to understand how Sonata works and I have a question. I saw something nice about their demo and I can not find in their documentation like to do. Maybe you can help me.

In the fields they arrive to color values according to criteria surely of the value of the latter I would like to know how to do. I put a small screen that I took on their site that help you maybe to understand my request. Colorful fields

I have a small form which I also put the code and I would like to be able to color in green the "client" in red "ex-client" and in blue "prospect" how am I supposed to do?

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->tab('General Information',array('class'=>'col-md-9'))
        ->with('', array('class'=>'col-md-9'))
        ->add('firstName', 'text')
        ->add('surname', 'text')
        ->add('address', 'text',array('required'=> false))
        ->add('email', 'email', array(
            'required' => false))
        ->add('Phone', 'text', array(
            'required' => false))
        ->add('birthdate', 'birthday', array('label' => 'Date of Birth','required'=>false))
        ->end()
        ->with('Others Informations',array('class'=>'col-md-3'))
        ->add('Status', 'choice', array(
            'choices' => array(
                'Client' => 'Client',
                'Ex-Client' => 'Ex-Client',
                'Prospect' => 'Prospect'),
        ))
        ->add('businessname', 'text', array('label' => 'Business Name','required'=>false))
        ->add('typeofbusiness', 'choice', array(
            'choices' => array(
                'Blank' => Null,
                'SE' => 'SE',
                'SA' => 'SA',
                'LLP' => 'LLP',
                'LTD' => 'LTD',
                'Payroll' => 'Payroll'),
            'label' => 'Type of buisness'
        ))
        ->end()
        ->end()
        ->tab('Comment',array('class'=>'col-md-12'))
        ->add('comments', 'textarea', array('required'=>false))
        ->end()
    ;
}



protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper
        ->add('surname')
        ->add('firstname')
        ->add('address')
        ->add('email')
        ->add('phone')
        ->add('birthdate', null, array(
            'label' => 'Date of birth (mm/dd/yyyy)'), 'sonata_type_datetime_picker', array(
            'format'                => 'MM/dd/yyyy',
            'dp_side_by_side'       => true,
            'dp_use_current'        => false,
            'dp_use_seconds'        => false,
        ))
        ->add('status')
        ->add('businessname')
        ->add('typeofbusiness')
        ->add('comments')
    ;

}

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('surname')
        ->add('firstname')
        ->add('address')
        ->add('email')
        ->add('phone')
        ->add('birthdate')
        ->add('Status')
        ->add('businessname')
        ->add('typeofbusiness')
        ->add('comments');
}

public function toString($object)
{
    return $object instanceof Client
        ? $object->getSurname()
        : 'Client'; // shown in the breadcrumb on the create view
}

}

Also in the installation and grip they make us create a BlogPost but nowhere I have defined anything and the boolean values are in red or green. I really do not understand how to do that.


Solution

  • You can do this by creating a custom template for your field(s)

    See here : https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/list_field_definition.html#custom-template