1

I am using flag and views to show a "like" flag in a view. The machine name of my flag is "like". I want to replace the text of the flag with a heart icon. When it is not flagged, it is empty and when flagged, it is filled with red color as happens generally. I do not want to show icon besides text and neither I want to transform my flag into a button. If you have used instagram, you must know that there is a heart icon for a "like" flag. When someone clicks it, it becomes red. Like when you favorite a tweet on twitter.

I found this code, but do not know how to use it for my case. I am not sure whether it is the right code to use.

function Your_theme_preprocess_flag(&$vars) {
  $class = ($vars['action'] == 'flag') ? '<i class="fa fa-heart-o">   </i>' : '<i class="fa fa-heart"></i>';
  $vars['link_text'] = $class;
  $title_wishlist = ($vars['action'] == 'flag') ? 'Add to wishlist' : 'Remove from wishlist';
  $vars['link_title'] = $title_wishlist;
}

Note: I know I have to put it in template.php file of my theme. If you see the post, I took this code from there, but I have multiple flags on my site for example "like" "follow" "bookmark" etc etc. So I want to use this code for the "like" flag. How can i do that I am also interested in learning how to add any icon other than heart and any flag I want.

  • Have a look at this ... – Pierre.Vriens Dec 15 '16 at 9:16
  • @Pierre.Vriens I do not want to show icon besides text and neither I want to transform my flag into a button. If you have used instagram, you must know that there is a heart icon for a "like" flag. When someone clicks it, it becomes red. Like when you favorite a tweet on twitter – Umair Dec 15 '16 at 13:35
  • 1
    OK, this comment makes sense. Though I suggest you integrate that in your actual question. If appropriate with a link also to my "this"-link, to help explain the difference (for somebody who might think is smells like a duplicate). – Pierre.Vriens Dec 15 '16 at 13:40
1

This code is needed in your template.php and a font-icon lybrary added like this one: http://fontawesome.io/icons/ There is a module for that to

  • I know I have to put it in template.php file of my theme. If you see the post above shared by pierre. I took this code from there, but I have multiple flags on my site for example "like" "follow" "bookmark" etc etc. So I want to use this code for the "like" flag. How can i do that? – Umair Dec 15 '16 at 13:39
  • @Umair : your prior comment may be worth integrating also in your question (as an additional refinement of your question). – Pierre.Vriens Dec 15 '16 at 13:43
  • 1
    @Umair you need to pass the "like" "follow" "bookmark" etc classes to views and generate <i class="fa fa-like"> and others. Look around drupal.org/project/fontawesome – eapo Dec 15 '16 at 14:47
  • I am sorry, what do you mean by "pass classes to views"? – Umair Dec 15 '16 at 15:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.