In a node, I have a multi-value field "field_MV" containing 3 items
I don't think it is important, but field_MV is of type "Entity reference revisions" and the items are paragraphs of only one type.
Each paragraph (item) have a field "field_quantity" containing a number.
Here is my exemple:
$node->field_MV[0]->field_quantity->value=5 (paragraph at delta 0)
$node->field_MV[1]->field_quantity->value=3 (paragraph at delta 1)
$node->field_MV[2]->field_quantity->value=7 (paragraph at delta 2)
In hook_node_presave, I would like to loop in the paragraphs to change their delta according the the value of field_quantity (descending)
Here is the result I would like to have:
$node->field_MV[0]->field_quantity->value=7 (previously paragraph delta 2)
$node->field_MV[1]->field_quantity->value=5 (previously paragraph delta 0)
$node->field_MV[2]->field_quantity->value=3 (previously paragraph delta 1)
My question is not how to order (I can handle this), but how to change the delta with something like:
$node->field_MV[0]->set("delta",1);
$node->field_MV[0]->save();