Created
November 10, 2014 13:35
-
-
Save webdevilopers/cfaf147928a1a5e17c94 to your computer and use it in GitHub Desktop.
Override edit twig template in SonataAdminBundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
sonata.admin.contract: | |
class: Acme\Bundle\ContractBundle\Admin\ContractAdmin | |
tags: | |
- { name: sonata.admin, manager_type: orm, group: "Contracts", label_catalogue: "messages", label: "Contracts" } | |
arguments: | |
- ~ | |
- Acme\Bundle\ContractBundle\Entity\Contract | |
- ~ | |
calls: | |
- [ setTemplate, [edit, AcmeContractBundle:ContractAdmin:edit.html.twig]] | |
- [ setSecurityContext, [@security.context]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Bundle\ContractBundle\Admin; | |
use Sonata\AdminBundle\Admin\Admin; | |
use Sonata\AdminBundle\Form\FormMapper; | |
use Symfony\Component\Security\Core\SecurityContextInterface; | |
class ContractAdmin extends Admin | |
{ | |
protected function configureFormFields(FormMapper $formMapper) | |
{ | |
$formMapper | |
->with('General') | |
->add('number', 'text') | |
->add('branch', 'sonata_type_model_autocomplete', array( | |
'property' => 'name', | |
'minimum_input_length' => 2 | |
)) | |
->end() | |
; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %} | |
{% block sonata_tab_content %} | |
<div class="{{ admin.formgroups.General.class|default('col-md-12') }}"> | |
<div class="box box-success"> | |
<div class="box-header"> | |
<h4 class="box-title"> | |
{{ admin.trans(admin.formgroups.General.name, {}, admin.formgroups.General.translation_domain) }} | |
</h4> | |
</div> | |
<div class="box-body"> | |
<div class="sonata-ba-collapsed-fields"> | |
{{ form_widget(form[admin.formgroups['General']['fields']['branch']]) }} | |
</div> | |
</div> | |
</div> | |
</div> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is good working