sonata-project / sonataadminbundle Goto Github PK
View Code? Open in Web Editor NEWThe missing Symfony Admin Generator
Home Page: https://docs.sonata-project.org/projects/SonataAdminBundle
License: MIT License
The missing Symfony Admin Generator
Home Page: https://docs.sonata-project.org/projects/SonataAdminBundle
License: MIT License
Seems like there's an issue with the 'sonata_type_collection' type. Let's imagine the following example (this is just a fictional example, but the scenario is exactly the same as what I have in my real application). We have 3 objects:
Now we want to be able, in the Admin, to create a Thread and at the same screen, add comments to that thread. This can be accomplished by doing something like:
// ThreadAdmin.php
protected $form = array(
'title',
'comments' => array(
'edit' => 'inline'
)
);
// CommentAdmin.php
protected $form = array(
'comment',
'user' => array('edit'=>'list')
);
// UserAdmin.php
protected $list = array(
'username' => array('identifier'=>true)
);
If you create a new Thread, you will be allowed to create new comments, inline, at the same screen, because it uses the 'sonata_type_collection'. Each Comment you add to the form will have a User element (ManyToOne relation), that will be rendered using a special widget where you can select a User via a lightbox.
So far so good, but there's a problem in this scenario. When you add a Comment, and then select a User and click save, it successfully save everything into the database, with all the relations. But after page reloads (or if you later go back to edit that Thread), all Comment entries will display BLANK user. If you change the user and save again, it correctly saves into the database, but again, once it reloads, it will be displayed BLANK. If you remove the 'edit'=>'list' and let it render a widget, it works fine. I tried to debug myself and I tracked the issue back to the "renderFormElement" method of SonataAdminExtension class. At line 181, it calls: return $this->output($fieldDescription, $template->render(array_merge($params, array( 'admin' => $fieldDescription->getAdmin(), 'object' => $object, 'field_description' => $fieldDescription, 'value' => $this->getValueFromFieldDescription($object, $fieldDescription, $params), 'field_element' => $children, 'base_template' => $fieldDescription->getOption('base_template', $base_template) )))); getValueFromFieldDescription in turn does: โฆ $value = $fieldDescription->getValue($object); // no value defined, check if the fieldDescription point to an association // if so, create an empty object instance // fixme: not sure this is the best place to do that if (!$value && $fieldDescription->getAssociationAdmin()) { $value = $fieldDescription->getAssociationAdmin()->getNewInstance(); } return $value finally, $fieldDescription->getValue($object) will end up calling $object->getUser(). But while debugging, I noticed that $object variable actually holds a PersistentCollection object instead of a real Comment object, therefore, getUser() getter is not available and we will end up with a brand new Comment instance (with everything blank). I'm not sure if I'm at the right track, but something is not right in this scenario. Also, there's another problem (maybe related to the 1st one). Say you add two Comments to the Thread, if you set the User for the 2nd Comment and click save, any validation attached to the User entity will fail, as if it's blank.
When adding a new relation to another new relation, it 404's on returning the new form entity to the first entity dialog. I'll attach some samples when I'm on my computer.
Hi,
Would it be possible to add the inline edition to many-to-many relations ?
Catchable fatal error: Argument 1 passed to Sonata\AdminBundle\Admin\Pool::__construct() must implement interface Symfony\Component\DependencyInjection\ContainerInterface, none given, called in SymfonyPR12/app/cache/dev/appDevDebugProjectContainer.php on line 1064 and defined in SymfonyPR12/src/Sonata/AdminBundle/Admin/Pool.php on line 26
I have a bundle:
autoload:
'APM' => DIR.'/../src',
appkernel:
new APM\TestDesignBundle\APMTestDesignBundle(),
creating Admin class, and write this in config.yml:
sonata_base_application:
entities:
post:
label: Test
group: test
class: APM\TestDesignBundle\Admin\TestAdmin
entity: APM\TestDesignBundle\Entity\Test
controller: TestDesignBundle:TestAdmin
after that i see dashboard with links list/add
but have an error when click on list
generated url: .../app_dev.php/admin/apm/testdesign/test/list
error:
ERR InvalidArgumentException: Bundle "TestDesignBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your AppKernel.php file? (uncaught exception)
i am trying in config.yml all combinations
controller: APM\TestDesignBundle:TestAdmin
controller: APMTestDesignBundle:TestAdmin
and so on - doesnt work.
What i miss?
Association might have an order field, for now the user need to edit the value in the embedded form
As recommended, a MenuBunble installation, as base to Admin Bundle installation, in the directory src/Knplabs/Bundle/MenuBundle causes errors.
The first one I noted is on app/console command that finish execution with an error:
"[Exception] The autoloader expected class "Knplabs\Bundle\MenuBundle\KnplabsMenuBundle" to be defined in file "<proj_root>/app/../src/Knplabs/Bundle/MenuBundle/KnplabsMenuBundle.php". You probably have a typo in the namespace or the class name."
(<proj_root> is my project root directory)
Then, if you made all configurations recommended, the bundle does not work.
I verify that:
I suggest that you make change 3. on AdminBundle code.
Hi ,
I am receiving this message in my list if my object doesn't have a target object set and returns a null :
Catchable fatal error: Method MyBundle\Entity\MyEntity::__toString() must return a string value in \beta1\vendor\twig\lib\Twig\Extension\Core.php on line 336
This is happening for the many-to-one or I believe for one-to-one.
BTW: I am using gedmo-doctrine-extensions -> nested trees, but I believe this has nothing to do with this.
I opened here the issue because I am not really sure where to go .
Please advise !
Thanks in advance !
I have validation rules in annotations like @Validation:MinLength(3), but BaseApplication forms don't handle them at all. It's extremaly useful to use this way of validation.
I have an entity with field MailTemplate::$type. The following form definition doesn't work but injects a string into MailTemplate::setType() when saving or editing an instance:
$choices = array();
foreach ($mailTypes AS $mailType) {
$choices[$mailType->getId()] = $mailType;
}
$form->add('type', array('label' => 'Mail-Typ', 'choices' => $choices), array('type' => 'choice'));
When adding a new relation to another new relation, it 404's on returning the new form entity to the first entity dialog. I'll attach some samples when I'm on my computer.
Currently you have to manually clear the cache if you added a new admin. You should add FileResources for each admin to the container/routing regeneration detection.
Namespace used in AdminBundle is something like "Knplabs\Bundle...." .
And the namespace in MenuBundle is "Knplabs\MenuBundle".
This is a conflict, which is no really good.
Following Symfony2 Best Pratices : http://docs.symfony-reloaded.org/guides/bundles/best_practices.html#directory-structure
The doc directory should be in the Resources directory.
Good job ;)
Hi,
Using "/{_locale}/admin" as prefix, but it doesn't work : "No route found for GET /fr/admin/dashboard".
What do you think about allowing config for list, form, field trought a yaml file like symfony 1 admin generator does ?
It could help people to adapt faster to this new version.
I can have a try on this feature if you are comfortable with this idea.
ie.
/login
/register/
/register/check-email
/register/confirm/{token}
/register/confirmed
/resetting/request
/resetting/send-email
/resetting/check-email
/resetting/reset/{token}
I'm afraid that actually only ORM is supported. I'm willing to introduce support for MongoDB. If I do so, will you consider merging?
In my humble opinion Admin classes aren't as handy as generator.yml in symfony 1.x Have you considered putting configuration to config file? In fact part of configuration is located in config.yml (class, entity, controller) so why not put fields, forms and other configs there, as well?
Hi,
After defining many to many relation i get an error while trying to edit one of entity:
Warning: Invalid argument supplied for foreach() in /home/krymen/workshop/netteam3_sandbox/src/vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Form/ValueTransformer/CollectionToChoiceTransformer.php on line 78
Any ideas how to fix it?
in one-to-many association, the Admin class must check if the model is set with orphan removal otherwise the delete option will not work
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 24 near 'id) as cnt FROM': Error: Class Sdv\MonitoringBundle\Entity\User has no field or association named id") in SonataAdminBundle:CRUD:base_list.html.twig at line 25.
And my YAML file for this table begins with :
Sdv\MonitoringBundle\Entity\User:
type: entity
table: user
fields:
idUser:
id: true
type: bigint
column: id_user
generator:
strategy: IDENTITY
nom:
type: string
length: 255
Could you help me please ?
I'm trying to setup a basic admin but I'm stuck on that error :
An exception has been thrown during the rendering of a template ("Route "admin_sf2mcq_core_category_create" does not exist.") in SonataAdminBundle:Core:dashboard.html.twig at line 30.
I believe I followed the tutorial carefully.
Here is my configuration
services:
sf2mcq.core.admin.category:
class: Sf2MCQ\CoreBundle\Admin\CategoryAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: sonata_blog, label: category }
arguments: [null, Sf2MCQ\CoreBundle\Entity\Category, Sf2MCQCoreBundle:CategoryAdmin]
Is is not clear to me If I have to change things in the tags field. name: foo fixes the issue but display nothing in the admin area...
Use lowerCamelCase and not underscores for attribute names.
The add_empty possibility on relation fields disapeared, or is not working anymore. Was that intentional ?
Playing with the template.layout parameter I found out that it does not work for the dashboard. The template extending the dashboard is hard written to be the one from SonataBaseApplicationBundle.
It seems the FieldMapper severly cripples the capabilities to work with the FormBuilder.
Why is this FieldDefinition stuff even needed? The Form framework has tons of extension points to define arbitrary view and form attributes through decorators and such. It seems the abstraction layer is using the "old" form API of the admin bundle and tried to wrap the new form framework in it.
Upon requesting any admin page, I get the following error:
Fatal error: Cannot use Symfony\Component\Routing\RouteCollection as RouteCollection because the name is already in use in /home/pascal/Projects/usmedia/UsMediaWebsite/vendor/bundles/Sonata/AdminBundle/Route/AdminPoolLoader.php on line 14
Apparently, The RouteCollection is initialized somewhere else previously.
A simple workaround is to load the Symfony\Component\Routing\RouteCollection as AdminRouteCollection (for example) and use that name instead.
The bundle should be usable when ACLs are disabled in the project, and maybe even when SecurityBundle is disabled. Currently, disabling the SecurityBundle breaks the AdminBundle, and not sure that disabling ACLs works.
Since the latest commits (probably Admin class refactoring), the breadcrumbs aren't displayed anymore.
I didn't have time to track down the reason why that is, maybe tomorrow if I have a moment I'll try and look into it. If it hasn't been fixed by then.
Currently _action reuses the $list parameter for a second purpose, which is relaly bad practice. It should be in its own $listActions = array() variable.
Hi ,
I am receiving this error when I am trying to do anything related to form use. I am also using a contact form and the error is not present.
I think this issue appears because there is no CSRF hidden field present in the form...!?
Although I have some constraints defined for my entity, submitted data in edit/create action aren't checked.
The button Add next to choice dropdowns for other entities crashes my firefox.
It trys to access the associationadmin.generateUrl, but that doesnt exist in the view.
I dont always have an admin for the associated entity, why generate a link to "edit" it?
Additionally this is a security problem here again, why allow to add the entity if you dont even know the associated entity provides an edit facility?
Hi,
I have a simple one-to-many relationship (Customer->Addresses), with no join table. Simply the address table has the foreign key 'customer_id'.
Though the tutorial example used a join table, I was able to load the form with no real problem. However the issue comes when saving or deleting an address.
When saving a new address, it will create the address in the table, but the customer_id field I noticed was not being populated.
So the the following edit screen appears with no associated addresses (though the address record is in the database).
My solution was to manually add this missing value in the 'preUpdate' function of my CustomerAdmin class:
foreach($object->getAddresses() as $address){
$address->setCustomer($object);
}
The same issue came when you wanted to delete an address, ticking the box correctly removes the item from the object in memory, but when flushed .... the record still exists in the database and so appears in the edit screen.
My solution to this was to add the following code to the 'preUpdate' function:
if($object->getId()){
$em = $this->modelManager->getEntityManager();
$query = $em->createQuery("SELECT a FROM Customer\Address a WHERE a.customer = '".$object->getId()."'");
foreach($query->getResult() as $address){
if(!$object->hasAddress($address)) $em->remove($address);
}
}
These updates seem less of a hack as I am overriding the 'preUpdate' function for 'CustomerAdmin', but I would have assumed that such functionality ought to have been auto-magic ;) .
Is there a better way to accomplish this?
Thanks
M.
The batch stuff is displayed in the list even if there are no batch actions.
Notice: Object of class Proxies\HWSPlatformBundleEntityMailTypeProxy could not be converted to int in /home/benny/code/php/wsnetbeans/lsl-ff-db/lsl-ff-db/vendor/symfony/src/Symfony/Component/Form/Util/FormUtil.php on line 18
This happens when trying to edit an entity with a many-to-one entity marked as 'choice'
Two errors are still lingering around since the change in Twigs way to handle translation :
Unexpected token. Twig was looking for the "with" or "from" keyword in SonataAdminBundle:CRUD:base_filter_field.html.twig at line 15.
Unexpected token. Twig was looking for the "with" or "from" keyword in SonataAdminBundle:CRUD:base_edit.html.twig at line 35.
The jQuery code is auto-generated currently, but it follows patterns. Additionally there is onclick="" used instead of proper jQuery event handling. This should be cleaned up alot and injecting the relevant data into the plugin using html5 data-* properties.
It would be great to have the installation according de Sf2 Standard Edition. So more people could start to use the bundle and do some little contributions.
Thanks
For now it is not possible to upload a file inside a modal window as ajax cannot send file need to use a iframe based solution
Currently it seems you have to redefine the type information in both form and list instead of having a central place Admin::$types where you define all the types and then re-use their names in the list and form description.
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.