fle/crud-bundle

Installs: 514

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

2.8.3 2016-11-28 09:18 UTC

README

Build Status

Dependency Status

Coverage Status

SensioLabsInsight

Overview

Installation

Add the bundle to your composer.json file:

require: {
    "jms/di-extra-bundle": "dev-master",
    "fle/crud-bundle": "1.*@dev"
}

Then run a composer update:

composer.phar update fle/crud-bundle

Register the bundle with your kernel in AppKernel::registerBundles():

<?php
$bundles = array(
    // ...
    new JMS\DiExtraBundle\JMSDiExtraBundle($this),
    new JMS\AopBundle\JMSAopBundle(),
    new FLE\Bundle\CrudBundle\FLECrudBundle(),
    // ...
);

Add Configuration in app/config/config.yml:

jms_di_extra:
    locations:
        bundles:
            - FLECrudBundle

twig:
    form_themes:
        - 'FLECrudBundle::Form/fields.html.twig'

Usage

{% extends 'FLECrudBundle::base.html.twig' %}

Filter

Custom Filter

<?php

use FLE\Bundle\CrudBundle\Annotation as CRUD;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ObjectRepository")
 * @CRUD\FormFilter(class="AppBundle\Filter\ObjectFilterType")
 */
class Object
{
    //...
}
<?php

use FLE\Bundle\CrudBundle\Filter\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Doctrine\ORM\QueryBuilder;

class ObjectFilterType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('articleType', ChoiceType::class, [
            'choices' => [
                'withArticle' => function (QueryBuilder $qb, $rootAlias) {
                    return $qb
                        ->andWhere("$rootAlias.article IS NOT NULL");
                },
                'all' => null
            ],
            'mapped' => false
        ]);
    }
}