Giter VIP home page Giter VIP logo

sonataannotationbundle's Introduction

Sonata Annotation Bundle

Adds Annotations for Sonata Admin.

The point is to reduce noise, having lots of admin classes with just mappings that don't do anything else should be avoided. Add annotations to your models and you are done. If you need something that is not covered by this bundle, create admin class instead.

This bundle was greatly inspired by IbrowsSonataAdminAnnotationBundle

PHP Version Latest Stable Version Latest Unstable Version

Build Status Coverage Status Scrutinizer Code Quality

Documentation

Installation

1. Add dependency with composer

composer require kunicmarko/sonata-annotation-bundle

2. Register the bundle in your Kernel

return [
    //...
    KunicMarko\SonataAnnotationBundle\SonataAnnotationBundle::class => ['all' => true],
];

Configuration

By default we scan all files in your src directory, if you save your entities somewhere else you can change the directory:

sonata_annotation:
    directory: '%kernel.project_dir%/src/'

How to use

Instead of creating class for Admin it is enough to just add annotation to your entity.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\FormField()
     * @Sonata\ListField()
     * @Sonata\ShowField()
     * @Sonata\DatagridField()
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;
}

Clear cache:

bin/console cache:clear

And you will see Admin appear in your sidebar.

Annotations

Admin

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;
use App\Admin\YourAdmin;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     managerType="orm",
 *     group="Category",
 *     showInDashboard=true,
 *     keepOpen=true,
 *     onTop=true,
 *     icon="<i class='fa fa-user'></i>",
 *     labelTranslatorStrategy="sonata.admin.label.strategy.native",
 *     labelCatalogue="App",
 *     pagerType="simple",
 *     controller=YourCRUDController::class,
 *     serviceId="app.admin.category",
 *     admin=YourAdmin::class,
 *     code="admin_code",
 * )
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

Access

If you are using role handler as described here you can add permission per role with this annotation.

This annotation can be used without Admin annotation present. If you have an admin class for your entity you can still use this annotation.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @Sonata\Access("ROLE_CLIENT", permissions={"LIST", "VIEW", "EXPORT"})
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

AddChild

You can read more about this here.

This annotation can be used without Admin annotation present. If you have an admin class for your entity you can still use this annotation.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 * @Sonata\AddChild(class=Post::class, field="category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Post")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Post
{
    /**
     * @ORM\ManyToOne(targetEntity="Category")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $category;
}

FormField

You can specify action option that would allow you to have different fields or have different configuration for the same field for create and edit action. If not set, field will be used for create and edit. Besides that, you are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\FormField(
     *      action="create",
     *      type="",
     *      options={},
     *      fieldDescriptionOptions={},
     *      position=1 
     * )
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @Sonata\FormField(
     *      type="",
     *      options={},
     *      fieldDescriptionOptions={},
     *      position=2
     * )
     *
     * @ORM\Column(name="description", type="string", length=255)
     */
    private $description;
    
    /**
     * @Sonata\FormField(
     *      action="create",
     *      type=TextType::class
     * )
     *
     * @Sonata\FormField(
     *      action="edit",
     *      type=TextareaType::class
     * )
     *
     * @ORM\Column(name="something", type="string", length=255)
     */
    private $something;
}

ShowField

You are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ShowField(
     *      type="",
     *      fieldDescriptionOptions={},
     *      position=1
     * )
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;
    
    /**
     * @Sonata\ShowField()
     */
    public function showThis(): string
    {
        return 'show value';
    }
}

ShowAssociationField

You are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ShowAssociationField(
     *      field="name",
     *      type="",
     *      fieldDescriptionOptions={},
     *      position=1
     * )
     *
     * @Sonata\ShowAssociationField(
     *      field="email",
     *      type="",
     *      fieldDescriptionOptions={},
     *      position=1
     * )
     *
     * @ORM\ManyToOne(targetEntity="Owner")
     * @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
     */
    private $owner;
}

ListField

You are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ListField(identifier=true) 
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @Sonata\ListField(
     *      type="",
     *      fieldDescriptionOptions={},
     *      identifier=false,
     *      position=1
     * )
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @Sonata\ListField(position=1)
     */
    public function listThis(): string
    {
        return 'list value';
    }
}

ListAssociationField

You are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ListAssociationField(
     *      field="name",
     *      type="",
     *      fieldDescriptionOptions={},
     *      identifier=false,
     *      position=1
     * )
     * 
     * @Sonata\ListAssociationField(
     *      field="email",
     *      type="",
     *      fieldDescriptionOptions={},
     *      identifier=false
     * )
     *
     * @ORM\ManyToOne(targetEntity="Owner")
     * @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
     */
    private $owner;
}

DatagridField

You are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\DatagridField(
     *      type="",
     *      fieldDescriptionOptions={},
     *      filterOptions={},
     *      fieldType="",
     *      fieldOptions={},
     *      position=1
     * )
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;
}

DatagridAssociationField

You are able to set the position of the field. Position 1 would be the first field to render and higher numbers after. If field doesn't have position, it will be rendered after all fields with position.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\DatagridAssociationField(
     *      field="name",
     *      type="",
     *      fieldDescriptionOptions={},
     *      filterOptions={},
     *      fieldType="",
     *      fieldOptions={},
     *      position=1
     * )
     *
     * @Sonata\DatagridAssociationField(
     *      field="email",
     *      type="",
     *      fieldDescriptionOptions={},
     *      filterOptions={},
     *      fieldType="",
     *      fieldOptions={}
     * )
     *
     * @ORM\ManyToOne(targetEntity="Owner")
     * @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
     */
    private $owner;
}

ExportField

You can add annotation to fields/method that you want to export, also you can add label for the field, if left blank field name will be used as label.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ExportField()
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @Sonata\ExportField("Custom Name")
     *
     * @ORM\Column(name="tag", type="string", length=255)
     */
    private $tag;

    /**
     * @Sonata\ExportField()
     */
    public function exportThis(): string
    {
        return 'export value';
    }
}

ExportAssociationField

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ExportAssociationField(
     *      field="name",
     *      label="Owner"
     * )
     *
     * @Sonata\ExportAssociationField(
     *      field="email",
     *      label="Email"
     * )
     *
     * @ORM\ManyToOne(targetEntity="Owner")
     * @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
     */
    private $owner;
}

ExportFormats

You can customize the export formats you want to allow, if this annotation is not present, all formats are shown.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;

/**
 * @Sonata\Admin("Category")
 *
 * @Sonata\ExportFormats({"json", "xml"})
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @Sonata\ExportField()
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;
}

AddRoute

Add custom routes to your admin class:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     controller=YourCRUDController::class
 * )
 *
 * @Sonata\AddRoute("import")
 * @Sonata\AddRoute(name="send_mail", path="{id}/send_mail")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

RemoveRoute

remove already existing routes:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     controller=YourCRUDController::class
 * )
 *
 * @Sonata\RemoveRoute("edit")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

ActionButton

This will add button next to your add button in a list view. Here you can find how the template should look like.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     controller=YourCRUDController::class
 * )
 *
 * @Sonata\AddRoute(name="import", path="/import")
 *
 * @Sonata\ActionButton("import_action_button.html.twig")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

DashboardAction

This will add button to your dashboard block for this entity. Here you can find how the template should look like.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     controller=YourCRUDController::class
 * )
 *
 * @Sonata\AddRoute(name="import", path="/import")
 *
 * @Sonata\DashboardAction("import_dashboard_button.html.twig")
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

ListAction

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     controller=YourCRUDController::class
 * )
 *
 * @Sonata\AddRoute(name="import", path="/import")
 *
 * @Sonata\ListAction("show")
 * @Sonata\ListAction("edit")
 * @Sonata\ListAction("delete")
 * @Sonata\ListAction(name="import", options={"template"="import_list_button.html.twig"})
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

DatagridValues

As explained here.

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Controller\YourCRUDController;

/**
 * @Sonata\Admin("Category")
 *
 * @Sonata\DatagridValues({"_sort_by":"p.name"})
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
    /**
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;
}

Extending The Admin

Sometimes you need to do something custom and this bundle can't help you with that but you still want to use annotations for most of the other stuff. You can extend our admin class KunicMarko\SonataAnnotationBundle\Admin\AnnotationAdmin and overwrite the methods you want.

<?php

namespace App\Admin;

use KunicMarko\SonataAnnotationBundle\Admin\AnnotationAdmin;

class YourAdmin extends AnnotationAdmin
{
    //do what you want
}

And then in your entity you just provide that class

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use App\Admin\YourAdmin;

/**
 * @Sonata\Admin(
 *     label="Category",
 *     admin=YourAdmin::class
 * )
 *
 * @ORM\Table
 * @ORM\Entity
 */
class Category
{
}

sonataannotationbundle's People

Contributors

greg0ire avatar kunicmarko20 avatar lordtyuk avatar lukepass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sonataannotationbundle's Issues

Support for groups, tabs and field order?

Hello and thanks for this awesome bundle!

Would it be possible to specify groups and tabs such as in admin classes?
Would it be also possible to get the option to reorder the fields?

Something like this in classes:

$formMapper->reorder(['name', 'description', 'collection', 'category']);

Thanks!

symfony3.4 Type error: preg_match() expects parameter 2 to be string, boolean given

Sonata packages

$ composer show --latest 'sonata-project/*'

sonata-project/admin-bundle              3.33.0 3.33.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.12.1 3.12.1 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.9.1  3.9.1  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.3.1  2.3.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2  1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.4.2  3.4.2  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.8.0  1.8.0  Lightweight Exporter library


$ composer show --latest 'symfony/*'
3.4

PHP version

$ php -v
# 7.1

NumberType not work in Annotation

i'm using last version this my code

use KunicMarko\SonataAnnotationBundle\Annotation as Sonata;
use Symfony\Component\Form\Extension\Core\Type\NumberType;

@Sonata\FormField(
     *     type=NumberType::class
     * )

admin work fine but only this filed show as text

[Type Error] Attribute "fieldOptions" of @Sonata\DatagridField expects a(n) string, but got array.

Environment

Symfony 3.4

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.48.0 3.48.2 The missing Symfony A...
sonata-project/block-bundle              3.15.0 3.15.0 Symfony SonataBlockBu...
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.16.2 3.17.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  3.0.0  Symfony SonataDatagri...
sonata-project/doctrine-extensions       1.2.0  1.3.0  Doctrine2 behavioral ...
sonata-project/doctrine-orm-admin-bundle 3.8.3  3.9.0  Symfony Sonata / Inte...
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExt...
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter ...
sonata-project/media-bundle              3.19.1 3.19.1 Symfony SonataMediaBu...
sonata-project/user-bundle               4.3.0  4.3.0  Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/monolog-bundle     v3.3.1  v3.3.1  Symfony MonologBundle
symfony/phpunit-bridge     v4.2.4  v4.2.8  Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.11.0 v1.11.0 Symfony polyfill backporting apcu...
symfony/polyfill-ctype     v1.11.0 v1.11.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu  v1.11.0 v1.11.0 Symfony polyfill for intl's ICU-r...
symfony/polyfill-mbstring  v1.11.0 v1.11.0 Symfony polyfill for the Mbstring...
symfony/polyfill-php56     v1.11.0 v1.11.0 Symfony polyfill backporting some...
symfony/polyfill-php70     v1.11.0 v1.11.0 Symfony polyfill backporting some...
symfony/polyfill-util      v1.11.0 v1.11.0 Symfony utilities for portability...
symfony/security-acl       v3.0.1  v3.0.2  Symfony Security Component - ACL ...
symfony/swiftmailer-bundle v2.6.7  v3.2.6  Symfony SwiftmailerBundle
symfony/symfony            v3.4.23 v4.2.8  The Symfony PHP framework

PHP version

$ php -v
PHP 7.2.17-1+ubuntu16.04.1+deb.sury.org+3 (cli) (built: Apr 10 2019 10:50:19) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.17-1+ubuntu16.04.1+deb.sury.org+3, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

Subject

Hello, I am trying to rewrite this piece of code using annotations:

    ->add('school', ModelAutocompleteFilter::class, [], null, [
        'property' => ['id', 'typology', 'name', 'city', 'address'],
    ]);

This is my annotation:

    /**
     * @ORM\ManyToOne(targetEntity="School")
     * @ORM\JoinColumn(referencedColumnName="id", nullable=false, onDelete="CASCADE")
     * @Sonata\DatagridField(
     *      type="doctrine_orm_model_autocomplete",
     *      fieldOptions={
     *          "property"="name"
     *      }
     * )
     * @Sonata\ListField()
     * @Sonata\FormField()
     * @Sonata\ShowField()
     */
    private $school;

Unfortunately it's giving me an exception:

[Type Error] Attribute "fieldOptions" of @Sonata\DatagridField declared on property AppBundle\Entity\UserSchool::$school expects a(n) string, but got array.

I think this is caused by fieldOptions not correctly accepting an array but only a string.

For now I managed to achieve the result using this "trick" (using filter options):

     * @Sonata\DatagridField(
     *      type="doctrine_orm_model_autocomplete",
     *      filterOptions={
     *          "field_options"={
     *              "property"="name"
     *          }
     *      }
     * )

Thanks.

Migrations issue once Package installed

As soon I am adding this package via Composer, all my migrations stop working in Symfony 4 and giving me errors on all of them.

bin/console make:migration
bin/console doctrine:migrations:diff

All migrations file created ARE in the src/Migrations folder, and are populated in the database.
But appear symfony just can'T find them anymore.

If I remove the package from my bundles.php, it work again without issues.
If I activate the package back, migrations issues come back.

I use Symfony 4.

Add ability to remove fields from when when create/edit

Sometimes a field can be only edited on create, not after. For example a User#username. I suggest adding two new properties to @Sonata\FormField() - create and edit, both are true by default

This will also allow to configure the field for create and edit differently in case anyone needs to

AddRoute documentation typo?

 * @Sonata\AddRoute(name="import", path="/import")
 * @Sonata\AddRoute(name="send_mail", path="{id}/send_mail")

First begins with a slash, second doesn't. So what's the correct way?

CRLF Line separators in Entities makes them ignored

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.43.0  3.43.0   The missing Symfony Admin Generator
sonata-project/block-bundle              3.13.0  3.13.0   Symfony SonataBlockBundle
sonata-project/cache                     2.0.1   2.0.1    Cache library
sonata-project/core-bundle               3.13.7  3.13.7   Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0   2.4.0    Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.3   1.1.3    Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.7.0   3.7.0    Symfony Sonata / Integrate Doctrine ORM into the SonataAd...
sonata-project/easy-extends-bundle       2.5.0   2.5.0    Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.10.0  2.0.0    Lightweight Exporter library
sonata-project/formatter-bundle          3.5.0   4.1.2    Symfony SonataFormatterBundle
sonata-project/media-bundle              3.16.3  3.16.3   Symfony SonataMediaBundle
sonata-project/user-bundle               4.2.3   4.2.3    Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                            v3.4.20 v4.2.1   Symfony Asset Component
symfony/browser-kit                      v3.4.20 v4.2.1   Symfony BrowserKit Component
symfony/cache                            v3.4.20 v4.2.1   Symfony Cache component with PSR-6, PSR-16, and tags
symfony/class-loader                     v3.4.20 v3.4.20  Symfony ClassLoader Component
symfony/config                           v3.4.20 v4.2.1   Symfony Config Component
symfony/console                          v3.4.20 v4.2.1   Symfony Console Component
symfony/css-selector                     v3.4.20 v4.2.1   Symfony CssSelector Component
symfony/debug                            v3.4.20 v4.2.1   Symfony Debug Component
symfony/debug-bundle                     v3.4.20 v4.2.1   Symfony DebugBundle
symfony/debug-pack                       v1.0.7  v1.0.7   A debug pack for Symfony projects
symfony/dependency-injection             v3.4.20 v4.2.1   Symfony DependencyInjection Component
symfony/doctrine-bridge                  v3.4.20 v4.2.1   Symfony Doctrine Bridge
symfony/dom-crawler                      v3.4.20 v4.2.1   Symfony DomCrawler Component
symfony/dotenv                           v3.4.20 v4.2.1   Registers environment variables from a .env file
symfony/event-dispatcher                 v3.4.20 v4.2.1   Symfony EventDispatcher Component
symfony/expression-language              v3.4.20 v4.2.1   Symfony ExpressionLanguage Component
symfony/filesystem                       v3.4.20 v4.2.1   Symfony Filesystem Component
symfony/finder                           v3.4.20 v4.2.1   Symfony Finder Component
symfony/flex                             v1.1.8  v1.1.8   Composer plugin for Symfony
symfony/form                             v3.4.20 v4.2.1   Symfony Form Component
symfony/framework-bundle                 v3.4.20 v4.2.1   Symfony FrameworkBundle
symfony/http-foundation                  v3.4.20 v4.2.1   Symfony HttpFoundation Component
symfony/http-kernel                      v3.4.20 v4.2.1   Symfony HttpKernel Component
symfony/inflector                        v3.4.20 v4.2.1   Symfony Inflector Component
symfony/intl                             v3.4.20 v4.2.1   A PHP replacement layer for the C intl extension that inc...
symfony/lts                              v3      v3       Enforces Long Term Supported versions of Symfony components
Package symfony/lts is abandoned, you should avoid using it. Use symfony/flex instead.
symfony/monolog-bridge                   v3.4.20 v4.2.1   Symfony Monolog Bridge
symfony/monolog-bundle                   v3.3.1  v3.3.1   Symfony MonologBundle
symfony/options-resolver                 v3.4.20 v4.2.1   Symfony OptionsResolver Component
symfony/orm-pack                         v1.0.5  v1.0.5   A pack for the Doctrine ORM
symfony/polyfill-apcu                    v1.10.0 v1.10.0  Symfony polyfill backporting apcu_* functions to lower PH...
symfony/polyfill-ctype                   v1.10.0 v1.10.0  Symfony polyfill for ctype functions
symfony/polyfill-intl-icu                v1.10.0 v1.10.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring                v1.10.0 v1.10.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php56                   v1.10.0 v1.10.0  Symfony polyfill backporting some PHP 5.6+ features to lo...
symfony/polyfill-php70                   v1.10.0 v1.10.0  Symfony polyfill backporting some PHP 7.0+ features to lo...
symfony/polyfill-util                    v1.10.0 v1.10.0  Symfony utilities for portability of PHP codes
symfony/process                          v3.4.20 v4.2.1   Symfony Process Component
symfony/profiler-pack                    v1.0.4  v1.0.4   A pack for the Symfony web profiler
symfony/property-access                  v3.4.20 v4.2.1   Symfony PropertyAccess Component
symfony/property-info                    v3.4.20 v4.2.1   Symfony Property Info Component
symfony/routing                          v3.4.20 v4.2.1   Symfony Routing Component
symfony/security                         v3.4.20 v4.2.1   Symfony Security Component
symfony/security-acl                     v3.0.1  v3.0.1   Symfony Security Component - ACL (Access Control List)
symfony/security-bundle                  v3.4.20 v4.2.1   Symfony SecurityBundle
symfony/serializer                       v3.4.20 v4.2.1   Symfony Serializer Component
symfony/serializer-pack                  v1.0.2  v1.0.2   A pack for the Symfony serializer
symfony/stopwatch                        v3.4.20 v4.2.1   Symfony Stopwatch Component
symfony/swiftmailer-bundle               v3.2.4  v3.2.4   Symfony SwiftmailerBundle
symfony/templating                       v3.4.20 v4.2.1   Symfony Templating Component
symfony/translation                      v3.4.20 v4.2.1   Symfony Translation Component
symfony/twig-bridge                      v3.4.20 v4.2.1   Symfony Twig Bridge
symfony/twig-bundle                      v3.4.20 v4.2.1   Symfony TwigBundle
symfony/validator                        v3.4.20 v4.2.1   Symfony Validator Component
symfony/var-dumper                       v3.4.20 v4.2.1   Symfony mechanism for exploring and dumping PHP variables
symfony/web-link                         v3.4.20 v4.2.1   Symfony WebLink Component
symfony/web-profiler-bundle              v3.4.20 v4.2.1   Symfony WebProfilerBundle
symfony/webpack-encore-pack              v1.0.3  v1.0.3   A pack for Symfony Encore
symfony/yaml                             v3.4.20 v4.2.1   Symfony Yaml Component

PHP version

$ php -v
PHP 7.2.10 (cli) (built: Sep 13 2018 00:47:25) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Subject

CRLF Line separators in Entities makes them ignored

Steps to reproduce

Create a new Entity with CRLF (windows) line separators

Expected results

Actual results

Entity files will be ignored because the following code in AutoRegisterCompilerPass.php line 83. wont find the namespace where in the file CRLF line separators were used

preg_match('/namespace (.*);$/', reset($namespaceLine), $match);

Error while compile container

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.35.1 3.35.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.12.1 3.12.1 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.9.1  3.9.1  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.3.1  2.3.1  Symfony SonataDatagridBundle
sonata-project/doctrine-orm-admin-bundle 3.6.0  3.6.0  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.8.0  1.8.0  Lightweight Exporter library

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                v4.0.8             v4.0.8             Symfony Asset Component
symfony/browser-kit          v4.0.8             v4.0.8             Symfony BrowserKit Component
symfony/cache                v4.0.8             v4.0.8             Symfony Cache component with PSR-6, PSR-16, and tags
symfony/class-loader         v3.4.8             v3.4.8             Symfony ClassLoader Component
symfony/config               v4.0.8             v4.0.8             Symfony Config Component
symfony/console              v4.0.8             v4.0.8             Symfony Console Component
symfony/css-selector         v4.0.8             v4.0.8             Symfony CssSelector Component
symfony/debug                v4.0.8             v4.0.8             Symfony Debug Component
symfony/dependency-injection v4.0.8             v4.0.8             Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.0.8             v4.0.8             Symfony Doctrine Bridge
symfony/dom-crawler          v4.0.8             v4.0.8             Symfony DomCrawler Component
symfony/dotenv               v3.4.8             v4.0.8             Registers environment variables from a .env file
symfony/event-dispatcher     v4.0.8             v4.0.8             Symfony EventDispatcher Component
symfony/expression-language  v4.0.8             v4.0.8             Symfony ExpressionLanguage Component
symfony/filesystem           v4.0.8             v4.0.8             Symfony Filesystem Component
symfony/finder               v4.0.8             v4.0.8             Symfony Finder Component
symfony/flex                 v1.0.78            v1.0.78           
symfony/form                 v4.0.8             v4.0.8             Symfony Form Component
symfony/framework-bundle     v4.0.8             v4.0.8             Symfony FrameworkBundle
symfony/http-foundation      v4.0.8             v4.0.8             Symfony HttpFoundation Component
symfony/http-kernel          v4.0.8             v4.0.8             Symfony HttpKernel Component
symfony/inflector            v4.0.8             v4.0.8             Symfony Inflector Component
symfony/intl                 v4.0.8             v4.0.8             A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/lts                  dev-master 6de50b2 dev-master 6de50b2 Enforces Long Term Supported versions of Symfony components
symfony/monolog-bridge       v4.0.8             v4.0.8             Symfony Monolog Bridge
symfony/monolog-bundle       v3.2.0             v3.2.0             Symfony MonologBundle
symfony/options-resolver     v4.0.8             v4.0.8             Symfony OptionsResolver Component
symfony/polyfill-apcu        v1.7.0             v1.7.0             Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu    v1.7.0             v1.7.0             Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring    v1.7.0             v1.7.0             Symfony polyfill for the Mbstring extension
symfony/polyfill-php56       v1.7.0             v1.7.0             Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70       v1.7.0             v1.7.0             Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72       v1.7.0             v1.7.0             Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-util        v1.7.0             v1.7.0             Symfony utilities for portability of PHP codes
symfony/process              v3.4.8             v4.0.8             Symfony Process Component
symfony/profiler-pack        v1.0.3             v1.0.3             A pack for the Symfony web profiler
symfony/property-access      v4.0.8             v4.0.8             Symfony PropertyAccess Component
symfony/property-info        v4.0.8             v4.0.8             Symfony Property Info Component
symfony/routing              v4.0.8             v4.0.8             Symfony Routing Component
symfony/security             v3.4.8             v4.0.8             Symfony Security Component
symfony/security-acl         v3.0.1             v3.0.1             Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.0.8             v4.0.8             Symfony SecurityBundle
symfony/security-csrf        v4.0.8             v4.0.8             Symfony Security Component - CSRF Library
symfony/stopwatch            v4.0.8             v4.0.8             Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.2             v3.2.2             Symfony SwiftmailerBundle
symfony/templating           v4.0.8             v4.0.8             Symfony Templating Component
symfony/translation          v4.0.8             v4.0.8             Symfony Translation Component
symfony/twig-bridge          v4.0.8             v4.0.8             Symfony Twig Bridge
symfony/twig-bundle          v4.0.8             v4.0.8             Symfony TwigBundle
symfony/validator            v4.0.8             v4.0.8             Symfony Validator Component
symfony/var-dumper           v4.0.8             v4.0.8             Symfony mechanism for exploring and dumping PHP variables
symfony/web-profiler-bundle  v4.0.8             v4.0.8             Symfony WebProfilerBundle
symfony/yaml                 v4.0.8             v4.0.8             Symfony Yaml Component

PHP version

$ php -v
PHP 7.2.4 (cli) (built: Apr  5 2018 00:37:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.4, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

Subject

in reader.xml there is config with bind key

        <defaults public="true">
            <bind key="$annotationReader" type="service" id="annotation_reader" />
        </defaults>

but when I change definition from

        <service id="sonata.annotation.reader.add_child" class="KunicMarko\SonataAnnotationBundle\Reader\AddChildReader" />

to

        <service id="sonata.annotation.reader.add_child" class="KunicMarko\SonataAnnotationBundle\Reader\AddChildReader" />
            <argument type="service" id="annotation_reader" />
        </service>

compiler pass and admin annotation works

Steps to reproduce

./bin/console cache:clear 

In AnnotationReaderTrait.php line 17:
                                                                               
  Type error: Too few arguments to function KunicMarko\SonataAnnotationBundle  
  \Reader\AddChildReader::__construct(), 0 passed and exactly 1 expected   

Expected results

compiler pass

Annotations with Sonata Media Bundle

Q A
Version 1.1

Support Question

I got a little bit stucked trying to use annotations with sonata media bundle. The following annotation gives me a headache and I couldn't find the problem


/**
 * @Sonata\FormField(
 * type=\Sonata\AdminBundle\Form\Type\CollectionType::class, 
 * options={
 * "by_reference"=false, * "entry_type"=\Sonata\MediaBundle\Form\Type\MediaType::class, 
 * "entry_options"={ 
 * "label"=false, 
 * "context"="default", 
 * "provider"="http://sonata.media .provider.file" * }, 
 * "allow_add"=true, 
 * "required"=false, 
 * } 
 * )
 *
 * @ORM\ManyToMany(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"}, fetch="LAZY") 
 * @ORM\JoinTable(name="contractproperty_files")
 */ 

private $files;

The error received:

(1/1) FatalThrowableError Type error: Too few arguments to function Sonata\MediaBundle\Form\Type\MediaType::__construct(), 0 passed in C:\devs\majoros\collector\vendor\symfony\form\FormRegistry.php on line 92 and exactly 2 expected in MediaType.php line 48 at MediaType->__construct()in FormRegistry.php line 92 at FormRegistry->getType('\Sonata\MediaBundle\Form\Type\MediaType')in FormFactory.php line 74 at FormFactory->createNamedBuilder('name', '\Sonata\MediaBundle\Form\Type\MediaType', null, array('required' => false, 'label' => false, 'context' => 'default', 'provider' => 'http://sonata.media .provider.file', 'block_name' => 'entry'))in FormBuilder.php line 106 at FormBuilder->create('name', '\Sonata\MediaBundle\Form\Type\MediaType', array('required' => false, 'label' => false, 'context' => 'default', 'provider' => 'http://sonata.media .provider.file', 'block_name' => 'entry'))in CollectionType.php line 39

Do you have any idea? Current versions from composer.json:
"php": "^7.1.3",
"kunicmarko/sonata-annotation-bundle": "^1.1",
"sonata-project/media-bundle": "^3.16",

Add documentation on how to extend the admin

This will be very useful in case a custom logic is required only in one of 2 methods of admin, and the rest can be configured using annotations

I also suggest renaming KunicMarko\SonataAnnotationBundle\Admin\Admin to KunicMarko\SonataAnnotationBundle\Admin\AnnotationAdmin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.