Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Adding custom icon sets to the social media module

Parent Feed: 

There are dozens of cool social media icon sets. Many designers want to create a custom set of icons to match their theme. The social media module was built with an icon set manager API.

The social media module for Drupal includes a default icon set called LevelTen Glossy. It also has built in support for a half dozen other free icon sets. Just download them, put them in the correct folder, and presto they are ready to use.

But what if you want to add your own icon set? Here is how to do it.

Adding a custom icon set social media

The socialmedia.icons.inc file contains the API. You can use that code as a starting point. You will want to implement the API in your own custom module such as example.module. The first step is to implement hook_socialmedia_iconset_info();. In your module you will want to add a function like this:

<br /> function example_socialmedia_iconset_info() {<br /> $icons['myicons'] = array(<br /> 'name' =&gt; 'My Icons', // name of your icon set<br /> 'publisher' =&gt; 'Me', // name of publisher<br /> 'publisher url' =&gt; 'http://www.mysite.com', // url to publisher's site<br /> 'styles' =&gt; array( // different variants of icons available<br /> '16x16' =&gt; '16x16',<br /> '32x32' =&gt; '32x32',<br /> '48x48' =&gt; '48x48',<br /> ),<br /> 'path callback' =&gt; 'example_icon_path_myicons, // callback for icon urls<br /> );<br /> return $icons;<br /> }<br />

This works very much like hook_menu();. It just tells the system about a new icon set and provides essential information.

The second element you will need is your path callback function. This needs to match the ‘path callback’ element in hook_socialmedia_iconset_info(). This function is to return the path where the icon can be found.

<br /> function example_icon_path_myicons($platform = 'twitter', $style = NULL) {<br /> $style = isset($style) ? $style : '32x32';<br /> $pt = array(<br /> 'googleplus' =&gt; 'google_plus',<br /> );<br /> $path = drupal_get_path('module', 'libraries') . 'socialmedia/icons/myicons/' . $style . '/' . ((isset($pt[$platform]))? $pt[$platform] : $platform) . '.png';<br /> return $path;<br /> }<br />

When you create your icon set, you will want to follow the standard naming convention which can be found in the socialmedia_icon_platforms() function. If you do have an icon name that does follow the convention, you can use the $pt array to define exceptions. For example, in the above code, the Google+ icon is named google_plus.png, not the standard of googleplus.png. So an exception was created in the $pt array.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web