Add an "image" field to entity "views"
My setup: I'm using Drupal 7 with lots of contrib modules (Chaos Tools, Views, IMCE, etc.) I'm not sure if Views are considered Entities right off the bat, but I'll be asking this question assuming that they are.
My question: How do I add a field to all Views that asks the admin for an image?
The context: I have a sidebar module that lists every View. I need them all to have thumbnails to the left of them.
What I've tried: I've tried looking all over the Field/CRUD APIs but I could not find anything that appends a field called "Image" to the end of the views_v开发者_StackOverflowiew table. I also tried watching some conferences e.g. DrupalCon but I couldn't find anything that was specific to my question.
Don't know exactly what you mean by "asks the admin for an image", but asuming you'd like to add a static image to a view you have the following options:
( probably easiest) add an image tag to a view block template. If you don't yet have a block template create one in your theme template folder and name it: block--views--{VIEW_BLOCK_DELTA}.tpl.php, copy the contents of the default block.tpl.php into the file and then add the img tag.
Login as admin, go to: structure > views and then click edit on a view you'd like to add image to. Go to fields section. Now it depends if you want to use the image path from cck field value OR you want to hardcode it, like you would in the 1st example.
CCK field way: ( first create a cck field of course), add it to your view fields list, go to rewrite result and tick "Rewrite the output of this field" and then add to textarea sometihing like that:
< img src="[YOUR_FIELD_NAME]">
You can also hardcode it, if you don't need it to be stored in a cck field in db: select a random field, click on it, go to go to rewrite result and tick "Rewrite the output of this field" and then add to textarea sometihing like that:
< img src="trololo.jpg"> [RANDOM FIELD NAME]
This would just append the image next to an existing filed, so with just a little styling you could achieve your goal quite quickly
精彩评论