I want to display images in my custom view. The view is build to display data from my custom table and not "node" table. I have managed to insert image related data like fileid(fid), file_mime etc in file_managed table from my custom form. But now how do i retreive it n my view ?
i know image insertion and retrieval is included in drupal 7 core but that works only if i am inserting all my data into "node" table using "content type". But this is not the case for me. I am inserting all my cotent data in custom table called "firms" (which ideally is supossedly to be inserted in node table).

Can somebody tell me which code should i use to retrieve the image and display it in my custom view ? also tell me in which file should i insert that code ?

Comments

Web Assistant’s picture

One way to do is to register/expose your custom table with Views. You can do this by using hooks_views_data() in a module. In the Views module folder, if you look at views/modules/node.views.inc, you can see how the node table is registered with Views, as an example.

The data module might be another alternative.

pushkaraj.khambayate@gmail.com’s picture

I have similar problem. I have created views by exposing my custom table with views using hooks_views_data. while i insert image from forms into this table, it gets stored in one of the coloumn as a blob field (i dont know why ?). and while i try to create view on this table all the data/ content of this table i am able to see in my view except this image field which is blob. please help, how can i see the image field in my custom view ?

Web Assistant’s picture

When the form uploads the image, would it not be better to save it to Drupal's file_managed table using file_save_upload and file_save? Then in your custom table, just put a reference to the file id (fid). In hooks_views_data you can join your custom table to the file_managed table and the image data will then be available in Views.

pushkaraj.khambayate@gmail.com’s picture

ok.. as suggested i created the references on my custom table to fid. Also joined custom table to file_managed in views. So now i can see image related data like filename, path (uri), filemime etc in views as fields. But i want my view to pick up the image from that path (uri) and display it. This is what is not happening. how do i tell the view that retrieve the file from the path which i have given you as a field.

Web Assistant’s picture

Can you not rewrite results as an image?

pushkaraj.khambayate@gmail.com’s picture

In Rewrite results i can see below options
1. Rewrite the output of this field (on check - opens a text box)
2. output this field as a link
3. Trim this field to maximum length
4. Strip HTML Tags
5. Remove whitespace
6. convert new lines to HTML
tags

How do i rewrite results as an image ?
am i missing something in my custom.views.inc file so that i get another option in rewrite results which says rewrite as an image ?
all i want to do must be very simple but somehow i am not able to get it. Appreciate all the efforts that you are putting to help me out.

Web Assistant’s picture

  • Add the File: Path field to your view.
  • Open the options for the field and check Display download path instead of file storage URI
  • In the Rewrite results section, check Rewrite the output of this field and enter something like the below, making sure you use the correct token.

<img src="[uri]" alt="" />

pushkaraj.khambayate@gmail.com’s picture

It worked. now i can see images instead of path. Thanks a lot !!

tilakabhijit’s picture

All these steps worked.. Thanks!