Drupal7, Coding

How to change/add custome file icon for uploaded files

In theme’s template.php file, we have to write below code :

function <theme-name>_file_icon($variables) {
global $base_url;
$file = $variables[‘file’];
$icon_directory = drupal_get_path(‘theme’, ‘<theme-name>’) . ‘/<file-icon-folder>’;
$mime = check_plain($file->filemime);
$icon_url = file_icon_path($file, $icon_directory);
$token = drupal_get_token(“file/{$file->fid}/download”);
return l(‘<img alt=”” class=”file-icon” src=”‘.$base_url.’/’.$icon_url . ‘” title=”‘ . $mime . ‘” />’ ,
“file/{$file->fid}/download” ,
‘query’ => array(‘token’ => $token) ,
‘html’ => TRUE


How drupal site backend should be for “Non Technical Editors”

I have been working on drupal for 4-5 years and been involved in development and theming. Started work on d6 then upgraded myself to work on drupal 7 too. I have delivered at least 20 drupal solutions to my customers in different areas but always felt it could be more awesome while handing over the site to them. I always felt, we as developers are always more concentrated on the site’s UI and functionality but not the admin part which should be the case too. On content editorial section, by default, Drupal provides lot of functionality which is not useful for normal users but we forget to hide/remove it. Also we can use some features, minor tweaks which could help clients enter content easily and quickly.

Lets start from the settings/features which should be hidden or modified so that content editors enter content easily.

User Roles :

Always use at least two user roles; one is admin role which can be used by the site developers, who have full access of the site and the other could be for editors/site admin who will add content to the site. User roles could be more based on your site-requirements. However, editors should not have lots of options, if they have then surely they will come up with new questions every day.

The suggestions below are only applicable for the Editorial role or the role which the client will be using for content creation/updation.

Tips while creating content type and fields :

1. While creating new content type, please make sure of entering proper name for content type so that when editors try to create content on their own, they will know which content link to be used.

2. Always set “disabled” option for “Preview before submitting” unless it’s required for some reason. Extra preview button will confuse them . They can preview the content in unpublished mode.

3. In “publishing options”, always check only “Published” option by default. But if your site has workflow implemented or you want that by default content should not get published, then you can uncheck it. Otherwise leave them as it is because these extra settings always confuse them.

4. If your site doesn’t have comment functionality so always uncheck setting from content type section so that this comment box does not show on the pages.

5. Node Title : By default the node title field name is “Title” but we can change it as content title or based on content type name (like news title, article title etc).

6. Always add help text for every field so that editors will know the use of the field and limitation of field too, if any.

7. Remove body field if this field is not required else change the name based on your requirement (it could be Description etc). Also remove “summary output” settings from this field.

8. While enabling RTE for body field always enable minimal RTE options unless the client has requested for any specific item. This is because if you give more options then it leads to confusion. Options could be :


  • Bold
  • Italic
  • Underline
  • Text Alignments
  • Order Listing
  • Link
  • Image Upload

9. Once you have defined a field, you can reuse it. For example: if you define a custom image field for one content type, and you need to have an image field with the same parameters on another content type, you can add the same field to the second content type, in the Add existing field area of the user interface. You could also add this field to a taxonomy vocabulary, comments, user accounts, etc.

Drupal Custom Blocks :

For the body field, set “Full HTML” as a default format and hide or disable this whole setting for editors so that the editor will see only this field with description text not the other options. Don’t use drupal custom block for showing some static content, like if you want to show some contact us information to the users of the site,don’t use drupal custom block. The reason behind this is, when they want to change it then either you will have to change it for them or you have to give the client block level permission which is very very dangerous as they can mess up the entire layout by changing order of the blocks. So in this situation instead of using drupal custom block, we can create a node and can show that node as a block using code/module/views so that can change in the content can be done by the client safely.

Views Block :

We all know drupal views and its super powers. We have used views blocks in almost every drupal page to show the latest articles, news etc. So suppose you are showing the latest 5 news items on the right side block of the page and editor wants to update the 3rd news item of the block. Now what you will suggest to them? Go to content on admin menu bar, then select news content type on type select list, find your news item title which you want to update in the given result.

Don’t you think its quite frustrating for them. For us, its just a matter of some clicks but for the editors who is not an expert, they may find it very difficult to update any existing news items. So in this situation, we can give them edit button on each item so that they can edit this news by directly click on edit button. This edit button will show up only for the editors and not to normal user. Enabling this edit button may be tricky but i am sure this will be very helpful for them.

Content and People Filtering

As an editors, its very difficult to search any content of the drupal site. By default, drupal provides admin/content page where content can be filter based on it “type”, its “status” like whether its “published” or “not published” etc. So need to provide a simple method for editors to find site content. We can use some modules here so that we can extend drupal’s built-in Content filtering tool like Content Management Filter (CMF) this module adds an easier way for administrators/editors to filter the content on a Drupal site for administration purposes. CMF is an alternative to the Administer >> Content management >> Content tool with these additional options:

  • Filter by author
  • Filter by user role
  • Filter by user status (active or blocked)
  • Filter by title or body substring
  • Filter by node created date
  • Displays a column in the content list with node creation time
  • Sort content list by any column: Title, Type, Author, Status, Time

Like content filtering, user search page also needs to be extend as on admin/people page, we can only search user by their role, permission and status. We need to add user fields as well here so that filtering of users based on the user.module fields and optionally the profile.module fields could be possible. For this we can use Advanced User module which provides these options.

The above mentioned suggestions might take some extra effort but these are very helpful for editors and enhance their efficiency and experience in creating/updating content without technical expertise.

If we are using CMS for building web applications then we should give site admins on full control of site content. This is the real benefit of cms site when they can update content freely.In my opinion, the data showing on web page, either it will be menu item text, left block, right block, main container or footer should be changeable by the editors without any Dev support.