Closed Devristo closed 9 months ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
We just hit this bug too, can confirm.
Do you want to try to debug it @daum ?
@VincentLanglet can try to look into it, but probably won't have enough time to do a deep dive until later next week, I saw a a couple of interesting issues using the debug project above as reference. If you add a second Chapter, it will let you add the "Page" in the second chapter, but still fail on the first one. It seems to keep resetting back to a single "Page" any subsequent clicks on the Second chapter. The first chapter still will error on any attempts to add a Page.
It seems like it's almost the embedded indexes of the Page's are incorrectly getting setup, but I'd need to dig into that further.
The issues seems that if in the submitted form there is unchecked checkboxes. Ping @VincentLanglet @daum
https://user-images.githubusercontent.com/1915265/121401443-66e18b00-c961-11eb-906b-d48bf5fe4427.mov
It could be interesting to dump the values $elementId
and $model
in the getElementAccessPath
, to see the differences.
if ($this->propertyAccessor->isReadable($model, $totalPath.$separator.$currentPath))
this return false, but can not figured it why. When try to read the value through propertyAccessor it thrown an error Cannot read property "workTimeSlots" from an array. Maybe you intended to write the property path as "[workTimeSlots]" instead.
This should be relation object, not array.
I cannot make work the reproducer... do you have one I can try ?
I would $model and other variable in order to understand more.
The $model (Venue) is pretty huge object. Here are the relations:
App\Entity\Venue:
type: entity
table: venues
id:
id:
type: integer
id: true
generator:
strategy: AUTO
oneToMany:
workTimes:
targetEntity: App\Entity\WorkTime
mappedBy: venue
cascade: ["persist"]
App\Entity\WorkTime:
type: entity
table: working_time
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
day:
type: smallint
column: dow
options:
unsigned: true
active:
type: boolean
column: is_active
options:
default: true
manyToOne:
venue:
targetEntity: App\Entity\Venue
inversedBy: workTimes
joinColumn:
name: venue_id
referencedColumnName: id
onDelete: CASCADE
nullable: false
oneToMany:
workTimeSlots:
targetEntity: App\Entity\WorkTimeSlot
mappedBy: workTime
orphanRemoval: true
cascade: ["persist", "remove"]
orderBy: { 'openAt': 'ASC' }
uniqueConstraints:
venue_dow:
columns: [ venue_id, dow ]
App\Entity\WorkTimeSlot:
type: entity
table: working_time_slots
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
openAt:
type: time
column: open_at
closeAt:
type: time
column: close_at
manyToOne:
workTime:
targetEntity: App\Entity\WorkTime
inversedBy: workTimeSlots
joinColumn:
name: work_time_id
referencedColumnName: id
onDelete: CASCADE
nullable: false
The form in VenueAdmin.php
$formMapper->tab('ui.tab.worktime')
->with('ui.box.worktime', array('class' => 'col-md-12'))
->add('workTimes', CollectionType::class, array(
'btn_add' => false,
'required' => false,
'by_reference' => false,
'type_options' => array(
'delete' => false,
'constraints' => [new Valid()]
),
'label' => false
), array(
'edit' => 'inline',
'sortable' => 'position',
'inline' => 'table',
'admin_code' => 'admin.worktime',
))
->end()
->end();
WorkTimeAdmin.php
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper->add('active', CheckboxType::class, array(
'label' => 'entity.venue.worktime.active',
'required' => false,
))
->add('day', ChoiceType::class, array(
'label' => 'entity.venue.worktime.day',
'multiple' => false,
'expanded' => false,
'disabled' => true,
'choices' => WorkTime::getDaysOfWeek(),
'choice_translation_domain' => 'messages',
'choice_label' => function ($choice, $key, $value) {
return sprintf("bot.dow.%s", $value);
}
))
->add('workTimeSlots', CollectionType::class, array(
'required' => false,
'type_options' => array('constraints' => [new Valid()]),
'label' => 'entity.venue.worktime.slots'
), array(
'edit' => 'inline',
'sortable' => 'position',
'inline' => 'table',
'admin_code' => 'admin.worktime_slot',
));
}
WorkTimeSlotAdmin.php
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('openAt', TimeType::class, array(
'label' => 'entity.venue.openAt',
'minutes' => array(00, 15, 30, 45)
))
->add('closeAt', TimeType::class, array(
'label' => 'entity.venue.closeAt',
'minutes' => array(00, 15, 30, 45)
));
}
Hope this help :)
if ($this->propertyAccessor->isReadable($model, $totalPath.$separator.$currentPath))
this return false, but can not figured it why. When try to read the value through propertyAccessor it thrown an errorCannot read property "workTimeSlots" from an array. Maybe you intended to write the property path as "[workTimeSlots]" instead.
This should be relation object, not array.
You said $this->propertyAccessor->isReadable($model, $totalPath.$separator.$currentPath)
return false.
In order to know why, you should dump
Then, since you don't have the error when ticking the checkbox, you should dump the same values with the checkbox ticked. If there is a difference in those values it could help us to understand the issue.
I cannot debug myself without a working reproducer.
Now I see that unchecked rows are not submitted at all. Then properyAccessor can't find them by their index and return false.
Empty row are not submitted.
You should try to removed disabled
to the day
field.
Use readonly instead.
Empty row are not submitted.
You should try to removed
disabled
to theday
field. Use readonly instead.
Now works, thank you @VincentLanglet!
Hello. What's the solution? Can I have an example? Thanks in advance.
As @VincentLanglet mentioned it, the issue was that I have empty rows in my child admin form. You can add an unmapped hidden field with some dummy data.
@kbosilkov Thank you. Checked, does not work. Added for the parent, then for the first child, then for the second child.
My field looked like this:
->add('fix404', HiddenType::class, array( "mapped" => false, 'empty_data' => '404', 'attr' => ['class' => 'hidden']))
A successful outcome can only be with a gradual approach, filling in the parent entity and the first subordinate one - saved, then added to the child - adding a second child entity. But at the last stage, even if you save, the data is not displayed either in the "table" or in "nature".
Environment
Sonata packages
Symfony packages
PHP version
Subject
Exception is thrown when adding a new item to a collection when the owner of the collection is new as well.
Steps to reproduce
Go to https://127.0.0.1:8000/admin/app/book/create
Press 'Add new' to add a new Chapter (note that clicking it a second time does NOT create a new Chapter row)
Immediately (without saving the Book) press 'Add new' to add a new Page
Expected results
The expected result is a new Page for the new Chapter.
Actual results
The AJAX call fails with an error like this:
Related issues
Seems to be the same as the closed #4752 issue.