Initial situation:
I have implemented the J4 ordering function in different views of a component. It works fine so far, although the component was not really rewritten for J4. .
Problem:
When I change the order of the main items, it correctly changes the ordering values in the column "ordering", but at the same time it deletes all connected custom fields (not the Joomla Custom fields, but its own kind of fields of the component).
My thoughts:
I figured out, that at the same time of storing the new ordering, a MySQL delete-query is running which is responsible for deleting all the custom fields. When I comment this query out, ordering works without losing the custom fields, but the custom fields are no longer stored at Item Edit.
I guess the logic is: when saving the Item in Edit-View, all old custom fields are deleted and saved new into the database, if any input for them is given. So they are not updated but completely deleted and newly stored. And because there are no field inputs given when ordering in the Items view, only the process of deleting is executed. Is that possible?
Solution? Does it make sense to do a work-around by surrounding the Delete-Query with an if-condition, only to work when in Item-Edit-View? If yes, how? What would be the condition statement to make sure it's only in the Edit-Viewm?
The Class with the Delete-Query:
class JCTableFieldInItem extends JTable
{
public function delete($pk = null, $fields_id = false, $extension = false)
{
$query = "DELETE a.*
FROM #__content_fields AS a
INNER JOIN #__cddir_fields AS b ON a.fields_id = b.id
WHERE a.content_id=".$pk." AND b.extension='" . $extension . "'";
$this->_db->setQuery($query);
// Check for a database error.
$this->_db->execute();
return true;
}