protected function shouldWriteFile(AbstractData $data, Request $request, Entity $entity, $entityName, $action)
    {
        $result = $data->getEvents()->shouldExecute($entity, 'before', $action);
        if (!$result) {
            return false;
        }
        $filesystem = $this->filesystem;
        $this->performOnFiles($entity, $entityName, function($entity, $entityName, $field) use ($filesystem, $request) {
            $file = $request->files->get($field);
            if ($file !== null && $file->isValid()) {
                $path     = $this->getPath($entityName, $entity, $field);
                $filename = $path.'/'.$file->getClientOriginalName();
                if ($filesystem->has($filename)) {
                    $filesystem->delete($filename);
                }
                $stream = fopen($file->getRealPath(), 'r+');
                $filesystem->writeStream($filename, $stream);
                fclose($stream);
            }
        });
        $data->getEvents()->shouldExecute($entity, 'after', $action);
        return true;
    }