protected function triggerBeforeSave(
        $query, EntityInterface $entity, array $data
    ) {
        $save = $query instanceof Insert
            ? (new Save($entity, $data))
                ->setAction(Save::ACTION_BEFORE_INSERT)
            : (new Save($entity, $data))
                ->setAction(Save::ACTION_BEFORE_UPDATE);

        /** @var Save $save */
        return Orm::getEmitter($this->getEntityClassName())->emit($save);
    }