0

In a content type I have a links fields using Link Module which has Title and URL set. This is useful to link the external files but I have a requirements also to link the files stored in Networked hard disk.

In an intranet system there is a drive eg: Z drive, which is same for all the systems in Intranet. The drive is actually an intranet server which stores all the doc files for everyone's use. When System Admins set-up new computers they set-up in such way that server drive is always Z drive in any computer (company preference).

I have a task to link to the file from Drupal site, lets say the file path is:
z:\popular-documents\how-to-use-pc.docx

When I give the above file path to link field, it changes the whole Link completely like:
http://localhost/Z%3A%5Cpopular-documents%5Chow-to-use-pc.docx

How can I use Link Module to link to the file and display the file link as it is instead of having http:// which link module adds by default.

The reason I have to use Link Module is I also want to be able to link it to external files too, lets say Google docs.

Not a requirement but good to have, if possible when the link is clicked it would open the file (I guess this is not possible from web interface).

  • 1
    Drive aliases like 'Z:' etc. are only symbolic in Windows. There must be a real network path as well, similar to `\\server\folder`. – Елин Й. Nov 21 '13 at 5:50
  • Yes, I am making the site for the intranet system. You are right that it has network path, but it'd also have alias as z: in any computer, so, the person must see the path via web interface. If there is an option to click and go to file its better, but that's not main requirement. I just want to put the path that users can see, and if they need to check the file they'll go through their My Computer... from OS. The main idea is to give them idea where the file resides. while using link module its not possible, as it takes only http link or converts it to http – user12947 Nov 21 '13 at 9:47
  • Have you looked at the stream wrapper hooks? With hook_stream_wrappers you would be able to handle uris like z://popular-documents/report.docx. – hampusn Nov 21 '13 at 11:07
  • @hampusn 'Z:/' is not a stream wrapper. – Елин Й. Nov 21 '13 at 12:05
  • I'm perfectly aware of that, z:// could still be created. – hampusn Nov 21 '13 at 12:11
2
+50

As I also stated in my comment, try to give a real network path. For example if the shared folder Z: is mapped to \\server\folder, the real network path of the file would be:

file:///\\server\folder\popular-documents\how-to-use-pc.docx

UPDATE:

According to Link module page:

Filter allowed protocols module This module allows you to change the default protocols that are set by Drupal to include new protocols like skype. The default protocols, for reference, are 'ftp', 'http', 'https', 'irc', 'mailto', 'news', 'nntp', 'rtsp', 'sftp', 'ssh', 'tel', 'telnet', and 'webcal'.

You can try this module to include 'file://' protocol.

  • I have tried this as you said, trying to give network path is changed to http://localhost://file// link by Link Module. I have tried other modules like url too but same issue, the URL module doesn't even support link without http:// – user12947 Nov 21 '13 at 9:50
  • Can you please write, what you exactly enter as URL, and into what the Link Module converts it? So that I can figure it out what is going on under the hoods. – Елин Й. Nov 21 '13 at 10:18
  • In the URL field, When I enter z:\popular-documents\how-to-use-pc.docx I get http://localhost/Z%3A%5Cpopular-documents%5Chow-to-use-pc.docx and when I enter file:///\\server\folder\popular-documents\how-to-use-pc.docx I get http://localhost/file%3A///%5C%5Cserver%5Cfolder%5Cpopular-documents%5Chow-to-use-pc.docx .... The http://localhost is added automatically, as I am in localhost at the moment – user12947 Nov 21 '13 at 10:30
  • I see, that means Link Module doesn't recognize the 'file://' prefix as a protocol. If there is no protocol defined it automatically adds 'http://' as the default protocol. – Елин Й. Nov 21 '13 at 11:53
  • I've found something interesting on the Link module project page. I'll update my answer with this information. Please check. – Елин Й. Nov 21 '13 at 11:56
0

I solved this but I admit its not sustainable solution (if anyone is looking for something like this).

  • Install Double Field Module
  • Made a field in my content type as Double Field.
  • Select both fields as string type of varchar 255
  • Make a label for content admin to know that s/he must use First field for Title and second field for URL or Filepath

Now when the content is created, it is saved in the database exactly what was entered.
eg:

File Title-------------------- Path
How to use PC ------------- z:\popular-documents\how-to-use-pc.docx
Drupal Guide ------------- https://drupal.org/documentation
Office Map ----------------- file://network-file/office-map.pdf

For only the link-like-field to be displayed as clickable links, I used jQuery in frontend to convert any text that starts with http(s):// as clickable link (like DSE does).

So, now I am not using Link Module.

There is performance implication if I ask jQuery to iterate through all the DOMs in the page, so, I decided to limit the iteration to only div that contains this My created Links, like:

$('#theLinkDivId li').html(function (_, html) {
                return html.replace(/((?:http|https):\/\/.+)$/g, '<a href="$1" target="_blank">$1</a>'); // with RegEx
            });

Confess

This is really not a good solution, as I have to expect the content admin to fill the information in right order, instead of dictating him via the programming logic I have to request (hope for) him not to be naughty.

It solved my problem as I am making the site for intranet system where external factors would not be playing security risks. So, use at your own risk.

I am keeping this question open as I expect somebody would come with brilliant solution for these kind of use cases.

  • Did you give a try to the Filter allowed protocols, which I mentioned in my answer? – Елин Й. Nov 23 '13 at 7:51
  • Yes yes, I tried that one, its really cool. But I am not sure if its better idea to use z: as protocol :D So, I had to figure out other options. – user12947 Nov 23 '13 at 11:27
  • You shouldn't use 'z:' as protocol, but 'file://'. 'Z:' is obviously not a protocol :) The problem with Link module was that it didn't recognize 'file://' as protocol, so that it added the 'http://' as prefix. If you would add the 'file://' protocol with the help of 'Filter allowed protocols' module, it might solved your problem. – Елин Й. Nov 23 '13 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy