Comments (6)
I don't think this was supposed to be supported previously because an admin is meant to be used for a persisted entity with an identifier.
In your example you can't access to the list, the show or the edit page of the Level1NestedDocAdmin or the Level2NestedDocAdmin. You only use them for you collectionType. (You're basically creating an whole admin just to have a formType when you could create your own formType.)
Looking at the stack trace, the getObject
of the Admin is not working, and that's the consequence of the fact you're using the admin for an entity without identifier. This rely on the modelManager
And if you look at the method of the modelManager https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle/blob/4.x/src/Model/ModelManager.php almost all the method won't work for your use case. You don't persist/flush an embedded and there is no sens to use find
, getIdentifiersValue
, ...
If something should/will be done for this "feature/fix" it should be done there IMHO. (Like a try catch of some isEmbedded checks if the documentManager provides some) ; but I'm not sure we should. @jordisala1991 WDYT ?
Another solution for you would be to implements a FakeModelManager doing nothing and using it for Embedded classes.
from sonatadoctrinemongodbadminbundle.
I transfer the issue to SonataDoctrineMongoDBAdminBundle
since I believe the check should be done here.
Maybe @franmomu can help.
@antonymous The getObject method is doing
final public function getObject($id): ?object
{
if (null === $id) {
return null;
}
$object = $this->getModelManager()->find($this->getClass(), $id);
if (null === $object) {
return null;
}
If the embedded has no identifier, was is the value passed to this method ?
If it's null
, it would have been handled by the early null check.
Unless we have a specific value, the fix will certainly be here
https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle/blob/4.x/src/Model/ModelManager.php#L76-L81,
with a different behavior for Embedded class (always returning null ?)
from sonatadoctrinemongodbadminbundle.
One way to workaround this I guess is to not create a Level2NestedDocAdmin
and create a Level2NestedDocType
with name
and in Level1NestedDocAdmin
add a CollectionType
from Symfony with Level2NestedDocType
as entry_type
.
from sonatadoctrinemongodbadminbundle.
I have common situation.
I have Category Document, it has "brands" embed collection of CategoryBrand documents, CategoryBrand document has "series" embed collection of BrandSeries documents.
Here are my documents:
#[MongoDB\Document(repositoryClass: CategoryRepository::class)]
class Category {
#[MongoDB\Id(type:Type::STRING, strategy:"NONE")]
private string $id;
#[MongoDB\Field(type: Type::STRING)]
private string|null $name;
#[MongoDB\EmbedMany(targetDocument: CategoryBrand::class)]
private $brands;
......
}
#[MongoDB\EmbeddedDocument]
class CategoryBrand
{
#[MongoDB\Id(type:Type::STRING, strategy:"NONE")]
private $id;
#[MongoDB\Field(type: Type::STRING)]
private $name;
#[MongoDB\EmbedMany(targetDocument: BrandSeries::class)]
private $series;
.........
}
#[MongoDB\EmbeddedDocument]
class BrandSeries
{
#[MongoDB\Id(type:Type::STRING, strategy:"NONE")]
private $id;
#[MongoDB\Field(type: Type::STRING)]
private $name;
#[MongoDB\Field(type: Type::STRING)]
private $description;
}
So I created CategoryBrandType, BrandSeriesType. I added BrandSeriesType as CollectionType in CategoryBrandType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
...
->add('series', CollectionType::class, ['entry_type' => BrandSeriesType::class])
...
}
I have CategoryAdmin
protected function configureFormFields(FormMapper $form): void
{
$form
->tab('Category')
->with('Common')
->add('id', null, array('label' => 'ID'))
->add('name', null, array('label' => 'Name'))
->add('order', null, array('label' => 'Order'))
->add('svgIcon', TextareaType::class, array('label' => 'svgIcon', 'required' => false))
->end()
..........
->end()
;
$form->tab('Brands', ['class' => 'col-md-8'])
->add('brands', CollectionType::class, [
'entry_type' => CategoryBrandType::class,
'allow_add' => true,
'allow_delete' => true
]
)
->end()
->end()
;
}
And until now all works just fine, I have an edit form, I can create/edit/delete Category data, I can create/edit/delete all CategoryBrand (in it's own tab) for category, I can even edit BrandSeries data for each CategoryBrand. But I don't get how to append create/delete functionality for that 2nd lvl embed collection (BrandSeries). And it would be just perfect if it was possible adding tabs into each CategoryBrand form.
from sonatadoctrinemongodbadminbundle.
I found the solution!
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
...
->add('series', CollectionType::class, [
'entry_type' => BrandSeriesType::class,
'allow_add' => true,
'allow_delete' => true
])
...
...
}
CollectionType should be not Symfony but Sonata\AdminBundle\Form\Type\CollectionType
from sonatadoctrinemongodbadminbundle.
So, this issue can be closed right?
The problem was trying to create admins for things that should only be FormTypes.
from sonatadoctrinemongodbadminbundle.
Related Issues (20)
- Filtering by choice where value is 0 fails to filter HOT 4
- Hash Type and Admin ? HOT 4
- Update Bugs Hash type for core23 HOT 2
- Form/form_admin_fields.htm l.twig miss # # sign HOT 2
- Unexpected identifier in edit_mongo_one_association_script.html.twig HOT 1
- Type error: trim() expects parameter 1 to be string, null given when adding DatagridFilters HOT 2
- Link to documentation is broken
- sonata export : DoctrineODMQuerySourceIterator is not well included HOT 3
- Cant delete documents from list view => ProxyQuery::setFirstResult and ProxyQuery::setMaxResults doesn't support null HOT 2
- Pager contains 1 abstract method and must therefore be declared
- Accessing property on embedded document via dot-notation works with filters but not list view HOT 7
- No metadata found for property `App\Document\SonataUserUser::$groups` HOT 3
- Add DateRangeFilter and DateTimeRangeFilter HOT 1
- Add ModelAutocompleteFilter HOT 1
- Form/Filter Templates broken with admin 3.98.2 HOT 1
- Stop using final method in Filters.
- Allow to set options on ProxyQuery
- SourceIteratorInterface on final class DataSource not exist on install HOT 2
- AbstractAdmin create method does not handle Model manager create exceptions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonatadoctrinemongodbadminbundle.