form_widget is populating empty - symfony

dump(form.location) and dump(form.room_id) is giving me following:
Like:
Symfony\Component\Form\FormView {#313280 ▼
+vars: array:31 [▼
"value" => "USA"
Symfony\Component\Form\FormView {#313280 ▼
+vars: array:31 [▼
"value" => "321"
But when in form_widget(form.locaiton), loction: USA is being populated but in form_widget(form_room_id) its empty.. Any reason for that?

Related

Firestore "too many index entries for entity" error: Which index?

We hit the "too many index entries for entity" error:
Error: 3 INVALID_ARGUMENT: too many index entries for entity
at Object.callErrorFromStatus (/workspace/node_modules/#grpc/grpc-js/build/src/call.js:31:19)
at Object.onReceiveStatus (/workspace/node_modules/#grpc/grpc-js/build/src/client.js:195:52)
at Object.onReceiveStatus (/workspace/node_modules/#grpc/grpc-js/build/src/client-interceptors.js:365:141)
at Object.onReceiveStatus (/workspace/node_modules/#grpc/grpc-js/build/src/client-interceptors.js:328:181)
at /workspace/node_modules/#grpc/grpc-js/build/src/call-stream.js:188:78
at processTicksAndRejections (node:internal/process/task_queues:78:11)
It seams I have to exempt a field from automatic indexing. But how do I know which field? The document has a lot of data with nested maps. Here is an example of the document:
{products: {
"p1": {id: "p1", :name "Product1", :group "g1"},
"p2": {id: "p2", :name "Product2", :group "g2"},
"p3": {id: "p2", :name "Product3", :group "g3"}
}}
Any suggestions which field would cause the error?
Override field products in firestore.indexes.json:
{
"fieldOverrides": [
{
"collectionGroup": "menu",
"fieldPath": "products",
"indexes": []
}
]}

SYMFONY Serializer - Decode XML file in an array, force type of a child element

I have a little problem when I want deserialize a XML File.
These are 2 differents file :
First file :
<allergenRelatedInformation>
<allergenSpecificationAgency>European Union</allergenSpecificationAgency>
<allergenSpecificationName>2003/89/EC</allergenSpecificationName>
<allergenStatement languageCode="fr">Blé</allergenStatement>
<isAllergenRelevantDataProvided>true</isAllergenRelevantDataProvided>
<allergen>
<allergenTypeCode>UW</allergenTypeCode>
<levelOfContainmentCode>CONTAINS</levelOfContainmentCode>
</allergen>
</allergenRelatedInformation>
Second File :
<allergenRelatedInformation>
<allergenSpecificationAgency>European Union</allergenSpecificationAgency>
<allergenSpecificationName>2003/89/EC</allergenSpecificationName>
<allergenStatement languageCode="fr">Arachides</allergenStatement>
<isAllergenRelevantDataProvided>true</isAllergenRelevantDataProvided>
<allergen>
<allergenTypeCode>NP</allergenTypeCode>
<levelOfContainmentCode>MAY_CONTAIN</levelOfContainmentCode>
</allergen>
<allergen>
<allergenTypeCode>AP</allergenTypeCode>
<levelOfContainmentCode>CONTAINS</levelOfContainmentCode>
</allergen>
<allergen>
<allergenTypeCode>UW</allergenTypeCode>
<levelOfContainmentCode>MAY_CONTAIN</levelOfContainmentCode>
</allergen>
</allergenRelatedInformation>
When I deserialize, I have for the first file :
"allergenRelatedInformation" => array:5 [▼
"allergenSpecificationAgency" => "European Union"
"allergenSpecificationName" => "2003/89/EC"
"allergenStatement" => array:2 [▶]
"isAllergenRelevantDataProvided" => "true"
"allergen" => array:2 [▼
"allergenTypeCode" => "UW"
"levelOfContainmentCode" => "CONTAINS"
]]
Second :
"allergenRelatedInformation" => array:5 [▼
"allergenSpecificationAgency" => "European Union"
"allergenSpecificationName" => "2003/89/EC"
"allergenStatement" => array:2 [▶]
"isAllergenRelevantDataProvided" => "true"
"allergen" => array:3 [▼
0 => array:2 [▼
"allergenTypeCode" => "NP"
"levelOfContainmentCode" => "MAY_CONTAIN"
]
1 => array:2 [▼
"allergenTypeCode" => "AP"
"levelOfContainmentCode" => "CONTAINS"
]
2 => array:2 [▼
"allergenTypeCode" => "UW"
"levelOfContainmentCode" => "MAY_CONTAIN"
]
]]]
My problem, it's "allergen" array are only one dimension in the first file, and array of array in the second... How I can tell in serializer it's always an array of array ?
I use :
Symfony\Component\Serializer\SerializerInterface;
With method :
$this->serializer->deserialize($this->fileXML, ProductSync::class, 'xml');
There is no way serializer would know by himself that "allergen" is always multidimensional array.
1. Use as_collection option for Serializer:
$this->serializer->deserialize($this->fileXML, ProductSync::class, 'xml', [
'as_collection' => true
]);
Result is always consistent, but it deserialize every element as array.
Source: https://symfony.com/doc/current/components/serializer.html#the-csvencoder-context-options
2. Custom transformation:
$allergen = $productSync['allergenRelatedInformation']['allergen'];
if (isset($allergen['allergenTypeCode'])) {
$productSync['allergenRelatedInformation']['allergen'] = [$allergen];
}
3. Change XML:
<allergenRelatedInformation>
<allergens>
<allergen>
<allergenTypeCode>NP</allergenTypeCode>
<levelOfContainmentCode>MAY_CONTAIN</levelOfContainmentCode>
</allergen>
<allergen>
<allergenTypeCode>UW</allergenTypeCode>
<levelOfContainmentCode>MAY_CONTAIN</levelOfContainmentCode>
</allergen>
</allergens>
</allergenRelatedInformation>
This way serializer know that "allergen" is one element of "allergens" element.

Cannot update to Drupal 8.7.1 because of taxonomy_post_update_make_taxonomy_term_revisionable

After running composer update drupal/core webflo/drupal-core-require-dev --with-dependencies to update to v8.7.1, and then running drush updb, the update fails here:
[notice] Update started: taxonomy_post_update_make_taxonomy_term_revisionable [4.77 sec, 33.46 MB]
[error] Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null: INSERT INTO {tmp_b3edd9taxonomy_term_field_data} (tid, revision_id, vid, langcode, name, description__value, description__format, weight, changed, default_langcode, status, revision_translation_affected) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11);
Array
(
[:db_insert_placeholder_0] => 1
[:db_insert_placeholder_1] => 1
[:db_insert_placeholder_2] => tags
[:db_insert_placeholder_3] => zxx
[:db_insert_placeholder_4] =>
[:db_insert_placeholder_5] =>
[:db_insert_placeholder_6] =>
[:db_insert_placeholder_7] =>
[:db_insert_placeholder_8] =>
[:db_insert_placeholder_9] =>
[:db_insert_placeholder_10] =>
[:db_insert_placeholder_11] => 1
)
in Drupal\Core\Database\Connection->handleQueryException() (line 689 of /mnt/www/html/optivode42/docroot/core/lib/Drupal/Core/Database/Connection.php). [7.12 sec, 45.21 MB]
[error] The entity update process failed while processing the entity type taxonomy_term, ID: 1. [8.17 sec, 45.24 MB]
[error] Update failed: taxonomy_post_update_make_taxonomy_term_revisionable [8.17 sec, 38.9 MB]
Other solutions suggested bad data in the taxonomy_term_field_data field, but that doesn't seem to be the problem here.
I checked taxonomy_term_field_data and there are no records where name is NULL, nor do I even have any records with langcode zxx, so I'm a bit at a loss now. Seems like there's nothing I can delete to fix this like in the other answers.
*Edit: I do have langcode zxx records in the taxonomy_term_data, so I deleted these records, and I get the same error, but with:
Array
(
[:db_insert_placeholder_0] => 2
[:db_insert_placeholder_1] => 2
[:db_insert_placeholder_2] => tags
[:db_insert_placeholder_3] => en
[:db_insert_placeholder_4] =>
[:db_insert_placeholder_5] =>
[:db_insert_placeholder_6] =>
[:db_insert_placeholder_7] =>
[:db_insert_placeholder_8] =>
[:db_insert_placeholder_9] =>
[:db_insert_placeholder_10] =>
[:db_insert_placeholder_11] => 1
)
I found that this is linked to a bug in the replicate-ui module which actually creates taxonomies without creating a real parent record in the taxonomy_index table.
Thus, I have opened up a bug report with the developer to fix this.
In the meantime, I actually upgraded to Drupal v8.6.16 since that has the security update that I needed, and I don't need to go all the way to v8.7 just yet.

Filter list of dicts by dict key

I have a dict of lists:
{
"foo": [
"A",
"B",
"C"
],
"bar": [
],
"baz": [
"D",
"E"
]
}
I would like to remove the dict element bar, so that only foo and baz remain. This does not even have to be dynamicly detecting empty lists, I know the element bar will be empty and I'll be happy to have a solution to remove it by name - or remove empty lists if that is easier.
I would like to do this with a filter, not in an Ansible loop. Any chance wihtout writing a custom filter? I have not found any built-in filter which appears like it could do this. reject and rejectattr work with lists of dicts, not with a dict containing lists.
---
- hosts: all
gather_facts: no
vars:
dict: { foo: [ A, B, C ], bar: [], baz: [ D, E ] }
dict_filtered: |
{%- set o={} %}
{%- for k, v in dict.iteritems() %}
{%- if v %}
{%- if o.update({k: v}) %}
{%- endif %}
{%- endif %}
{%- endfor %}
{{ o }}
tasks:
- debug:
var: dict_filtered
sample session:
$ ansible-playbook -i localhost, playbook.yml
PLAY [all] ********************************************************************
TASK: [debug ] ****************************************************************
ok: [localhost] => {
"var": {
"dict_filtered": {
"baz": [
"D",
"E"
],
"foo": [
"A",
"B",
"C"
]
}
}
}
PLAY RECAP ********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0

Why tree is invalid?

I have a entity that use doctrine extension, tree behaviuor, i found problems in tree and don't know it's reason.
my entity:
MyEntity:
type: entity
gedmo:
tree:
type: nested
id:
id:
type: integer
generator:
strategy: AUTO
fields:
# ...
lft:
type: integer
gedmo:
- treeLeft
rgt:
type: integer
gedmo:
- treeRight
lvl:
type: integer
gedmo:
- treeLevel
root:
type: integer
gedmo:
- treeRoot
createdAt:
column: created_at
type: datetime
gedmo:
timestampable:
on: create
updatedAt:
column: updated_at
type: datetime
gedmo:
timestampable:
on: update
oneToMany:
children:
targetEntity: MyEntity
mappedBy: parent
orderBy:
lft: ASC
manyToOne:
parent:
targetEntity: MyEntity
inversedBy: children
joinColumn:
name: parent_id
referencedColumnName: id
onDelete: "restrict"
gedmo:
- treeParent
tree problem:(reported by verify() method)
0 => "index [8], duplicate on tree root: 1"
1 => "index [9], duplicate on tree root: 1"
2 => "index [20], duplicate on tree root: 1"
3 => "index [21], duplicate on tree root: 1"
4 => "node [8], left is greater than right on tree root: 1"
5 => "node [10] left is less than parent`s [7] left value"
6 => "node [16] right is greater than parent`s [7] right value"
7 => "node [19] right is greater than parent`s [6] right value"
8 => "node [20] right is greater than parent`s [6] right value"
9 => "node [21] right is greater than parent`s [6] right value"
10 => "node [22] right is greater than parent`s [6] right value"
11 => "node [23] right is greater than parent`s [6] right value"
12 => "node [24] right is greater than parent`s [6] right value"
13 => "node [31] left is less than parent`s [30] left value"
14 => "node [35] left is less than parent`s [8] left value"
15 => "node [36] left is less than parent`s [8] left value"
table data
I've encountered exactly the same issue. Perhaps this answer will help someone else.
Gedmo/Tree with the nested set executes changes in leaf nodes before the deletion transaction begins. Therefore, even the transaction is rollbacked, the updated changes persist. To resolve that you should start the transaction manually before.
Ref. https://github.com/doctrine-extensions/DoctrineExtensions/issues/1062 & https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/transaction-safety.md
I found problem, when i delete a entity by $em->remove method, doctrine extension assume that onDelete=cascade for entity & change lft & rgt values of tree, then run query for removing of entity(and all children), but my entity have onDelete=restrict, then lft & rgt values are updated, but children is not deleted and this raise error in tree

Resources