Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / ContractAdmin.php
Created November 10, 2014 13:35
Override edit twig template in SonataAdminBundle
<?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
@webdevilopers
webdevilopers / Version20141112104658.php
Last active August 29, 2015 14:09
Schema commands not executed in postUp() method while prepared statements in queries are executed even with --write-sql option in Doctrine Migrations
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@webdevilopers
webdevilopers / acme_layout.html.twig
Last active August 29, 2015 14:09
Override FOSUserBundle resp. SonataUserBundle resp. ApplicationSonataUserBundle layout.html.twig template
{% extends "TwigBundle::layout.html.twig" %}
{% block head %}
<link rel="icon" sizes="16x16" href="{{ asset('favicon.ico') }}" />
{% block stylesheets %}
<link rel="stylesheet" href="/bundles/sonatacore/vendor/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('/bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css') }}" />
@webdevilopers
webdevilopers / DormerRequestType.php
Last active August 29, 2015 14:10
Assert entity is selected if checkbox is checked with Expression Constraint - Symfony2 Form Validation
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\FormBuilderInterface;
class DormerRequestType extends BaseRequestType
{
public function buildForm(FormBuilderInterface $builder, array $options) {
switch ($options['flow_step']) {
@webdevilopers
webdevilopers / routing.yml
Last active June 20, 2020 09:01
Security Config for FOSUserBundle with SonataUserBundle with SonataAdminBundle
admin:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
soanata_user:
@webdevilopers
webdevilopers / BundleAdmin.php
Last active January 11, 2016 09:09
Sonata Admin Role Handler isGranted usage in parent Admin Class
<?php
class BundleAdmin extends Admin
{
protected $parentAssociationMapping = 'contract';
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('date', 'date');
@webdevilopers
webdevilopers / DormerRequestType.php
Last active January 13, 2016 15:15
Dynamically set field type option readonly to false on choice if dependent radio button is checked true using symfony2
<?php
use Symfony\Component\Form\AbstractType;
class FooBarType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('addFoo', 'choice', array(
'choices' => array(
@webdevilopers
webdevilopers / BundleController.php
Last active May 22, 2018 20:23
Rendering Highcharts in wkhtmltopdf generated PDF using the symfony2 bundles ObHighchartsBundle and KnpSnappyBundle
<?php
namespace Plusquam\Bundle\ContractBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
@webdevilopers
webdevilopers / PriceQuoteRequest.php
Last active August 29, 2015 14:13
How to use Symfony2 Validation Constraint Callback with validation groups to validate a single property
<?php
namespace Acme\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* PriceQuoteRequest
@webdevilopers
webdevilopers / .htaccess
Created January 22, 2015 08:49
How to use Symfony2 Full Stack and Components with legacy PHP flat app
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On