I would change this block with

    $dataId = $request->data($model->alias . '.' . $model->primaryKey) ?: $request->data($model->primaryKey);