protected function createAttachmentLink(File $file, AttachableObjectInterface $object, $fieldName, Attachment $attachment, $customFilename = null)
    {
        if ($file instanceof UploadedFile)
        {
            $extension = $file->getClientOriginalExtension();
            $filename = $file->getClientOriginalName();
            $basename = basename($filename, '.'.$extension);
        }
        else
        {
            $extension = $file->getExtension();
            $filename = $file->getFilename();
            $basename = $file->getBasename('.'.$extension);
        }
        
        if (null !== $customFilename)
        {
            $filename = $customFilename;
            $basename = basename($filename, '.'.$extension);
        }
        
        $link = new AttachmentLink();
        $link
            ->setAttachment($attachment)
            ->setModelName($object->getAttachableClassName())
            ->setModelId($object->getAttachableId())
            ->setModelField($fieldName)
            ->setFileName($filename)
            ->setFileExtension($extension)
            ->setCustomName($basename)
        ;
        
        return $link;
    }