kunicmarko20 / sonataannotationbundle Goto Github PK
View Code? Open in Web Editor NEWAnnotations for Sonata Admin
License: MIT License
Annotations for Sonata Admin
License: MIT License
$ 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 -v
# 7.1
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
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
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!
I forgot to add a call to addChild
on admin class service when you add ParentAssociationMapping annotation but there is a different problem. You can basically add a child to any admin, even if they are not connected.
Waiting for resolution of sonata-project/SonataAdminBundle#5052 to see how will I fix this.
* @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?
$ 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
$ 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 -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
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
./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
compiler pass
$ 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
$ 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 -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
CRLF Line separators in Entities makes them ignored
Create a new Entity with CRLF (windows) line separators
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);
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
Symfony 3.4
$ 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
$ 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 -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
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.
I am creating this issue so that I can target it instead of #31 because this just for the position field.
Thanks.
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.
Q | A |
---|---|
Version | 1.1 |
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",
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.