Closed watari closed 2 years ago
I think, that problem can be fixed if:
sonata_type_model_autocomplete.html.twig:112
from {% if sonata_admin.admin is not null %}
to {% if sonata_admin.admin is not empty %}
Admin
class.In my case with this changes problem was fixed. What do you think about this solution? Will it brake something?
I have been experiencing the same problem and @watari's fix works for me. To avoid modifying sonata_type_model_autocomplete.html.twig, I instead extended it, overrode the block sonata_type_model_autocomplete_ajax_request_parameters, and set the 'template' option of ModelAutocompleteType.
Same problem here. I did @jean-gui fix.
I think we need to go with solution 1
- condition will be changed sonata_type_model_autocomplete.html.twig:112 from {% if sonata_admin.admin is not null %} to {% if sonata_admin.admin is not empty %}
If we check FormTypeFieldExtension (that defines the sonata_admin field), in Line 51 the admin
field inside sonata_admin
is being set to null. Later on the same function its value is replace by the admin in the FieldDescription, see Line 66.
So far ok, but in Line 102, if the field is a child, then its value is replaced by false. Which is causing the error.
As far as I understand, the false
value was added in this commit 20b4c3b68e42f165a441b42d3e5c35e598cc73e6. @rande can you help us understand what is the best solution in this case?
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
It is no longer relevant for me. I fixed it in project locally and published solution in comments here with questions related to it.
The workaround works well but the problem is still there.
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.
This is still an issue. @jean-gui what does your extended and overridden block look like exactly? Thanks for any help getting this solution to work!
@dilloncoffman It's been a while since I've looked into this, but here is what I have in my template, the block is copy-pasted from SonataAdmin/Form/Type/sonata_type_model_autocomplete.html.twig L100-139 with a single change, the last line in the snippet below:
{% extends '@SonataAdmin/Form/Type/sonata_type_model_autocomplete.html.twig' %}
{% block sonata_type_model_autocomplete_ajax_request_parameters %}
return {
//search term
'{{ req_param_name_search }}': term,
// page size
'{{ req_param_name_items_per_page }}': {{ constant('App\\Kernel::ITEMS_PER_PAGE') }},
// page number
'{{ req_param_name_page_number }}': page,
// admin
{% if sonata_admin.admin is not empty %}
...
Should have been fixed by https://github.com/sonata-project/SonataAdminBundle/pull/7609
Environment
Sonata packages
Symfony packages
PHP version
Subject
Hi there! I getting Twig runtime error "Impossible to access an attribute ("uniqid") on a boolean variable ("")." when try to use
ModelAutocompleteType
for field in entity that belong to nested collection in form.Similar problem was previously reported here (https://github.com/sonata-project/SonataAdminBundle/issues/3727). I tried to search for solutions but failed to find any. Maybe I just doing something wrong, but I cant figure it out.
In my case I have
Bill
andBillLine
entities withOne-to-Many
relation. Also thereType
entity to whichBillLine
referenced withMany-to-One
. I tried to create form in which Bill with related bill lines will be created. In this form I wanted to have autocomplete fortype
field. This field is associated withType
entity. For this purpose I tried to useModelAutocompleteType
. For configuring form block for eachBillLine
instance I created custom Symfony form type. As options for this form type I passed from Admin classmodel_manager
and reference to parent admin instance.Steps to reproduce
ModelAutocompleteType
CollectionType
for field with "nested" entities.entry_type
custom type for "nested" entity class.Expected results
Form successfully created. When New Collection item is added, auto-complete in item-related block work correctly.
Actual results
Twig runtime error "Impossible to access an attribute ("uniqid") on a boolean variable ("")."