symfony2admingenerator / AvocodeFormExtensionsBundle

(old-legacy) Symfony2 form extensions for Admingenerator project (also working standalone!)
Other
48 stars 31 forks source link

Problem on collection_upload edit #158

Closed ndoulgeridis closed 9 years ago

ndoulgeridis commented 9 years ago

Hey,

I am trying collection_upload. Parent form has this:

$builder->add('images', 'afe_collection_upload', array(
        'required' => false,
        'nameable' => false,
        'primary_key' => 'id',
        //'nameable_field' => null,
        'sortable' => false,
        'type' => new FooHasImageType(),
        'options' => array('data_class'=>'FooBundle\Entity\Relationships\FooHasImage'),
        'previewMaxWidth' => 160,
        'previewMaxHeight' => 120,
        'acceptFileTypes' => '/^image\\/(gif|jpeg|png)$/',
        'allow_add' => true,
        'allow_delete' => true,
        'error_bubbling' => false,
        'uploadRouteName' => 'foo_path', // must be the same as in the configuration
        'autoUpload' => true,
        'label' => "field.images",
    ));

Child Form has this:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('id', 'hidden')
        ->add('name');
}

Everything works fine except on edit if i keep the images already uploaded there and sumit form I get this error:

NoSuchPropertyException in PropertyAccessor.php line 456: Neither the property "id" nor one of the methods "addId()"/"removeId()", "setId()", "id()", "set()" or "call()" exist and have public access in class "...".

Its logical because child form has id field which in entity is the PK and there is no setId and name doenst not exist in Entity.

Any idea what I am doing wrong?

EDIT:

In this example here:

https://github.com/symfony2admingenerator/AvocodeFormExtensionsBundle/issues/32

You set id as integer, if I do so I don't get error but in edit mode I get a filed to set id... But If i set id hidden I get mapping error :(

ndoulgeridis commented 9 years ago

It seems fixed by adding mapped=>false

->add('id', 'hidden', array("mapped"=>false))
ioleo commented 9 years ago

@crash21 yes, this fix is very good for this

The id property is rendered (and used) by the UploadCollectionListener to handle "deleting".

If an item with id X is in the collection... but id X is not present in POST, then the eventlistener understands that item X has been removed (via JS) on client side and should be also removed on server side.

So, the id is never meant to be mapped (or changed), it's just used as a unique identifier for the "delete" functionality implementation.

ndoulgeridis commented 9 years ago

Nice!

Something else suspicious is that in template this is hardcoded:

<label class="btn btn-toggle disabled input-append">
            <input type="checkbox" class="toggle">
        </label>

So the checkbox to select all files is every time disabled (both the master and the children checkboxes has disabled class..)

Any ideas about this?