I answer to myself. finally i've solved my issue by fixing 2 points:
The first point was a mistake from my side : the "value" used in the definition must be a "string". In my code, i used an entity reference id defined as an integer.
The second point was linked to my select field defined as a "multiple" one. To address this point it's necessery to alter the "compare" function of core/misc/states.js. I add this js library into my module
/**
* @file
* Extends core/misc/states.js.
*/
(function($) {
//correction core : can't add a #states on a select with multiple = true
function _compareCustom(a, b) {
if (a !== "undefined" && typeof b === 'object' && b instanceof Array) {
if (b.includes(a)) {
return true;
}
}
if (a === b) {
return typeof a === 'undefined' ? a : true;
}
return typeof a === 'undefined' || typeof b === 'undefined';
}
//hack : surcharge function compare from core/states.js to use _compareCustom instead of _compare2
Drupal.states.Dependent.prototype.compare = function compare(reference, selector, state) {
var value = this.values[selector][state.name];
if (reference.constructor.name in Drupal.states.Dependent.comparisons) {
return Drupal.states.Dependent.comparisons[reference.constructor.name](reference, value);
}
return _compareCustom(reference, value);
};
})(jQuery);
This solution works with all drupal version from 8.x to 10.3.1.
Sorry, but the last version of Drupal 10.3.1 break all my "select" based conditional fields.
My conditional fields works well on Drupal 10.2.6
Here an extract from my form where the field_child is visible when the taxonomy term (tid:1234) is selected
$form['field_child']['#states'] = [
'visible' => [
['select[name="field_parent[]"]' => '1234',
],
];
I have the same issue with Drupal 10.3.0 (and 10.2.x).
My website is also a multilanguage one and "drush cim" fail on content moderation field import.
The last patch in the proposed thread generates a different error. In the thread they mention that the moderation state field is not a translatable one and this is probabably the cause of the error.
#17 partially worked for me in Drupal 10.3.0 and 10.2.3
I use an aggregartion on content moderation states field with the count aggrator in combination with the chart module.
I've solved my issue with tha hook_views_query_alter
function hook_views_query_alter(ViewExecutable $view, $query):void
{
//Fix bug for views on content moderation
if(!empty($query->fields)){
foreach($query->fields as $kf=>$field){
if(isset($field['function'])){
if($field['field']=='moderation_state'){
$query->fields[$kf]['table']= 'content_moderation_state';
}
}
}
}
}