Adding custom icon sets to the social media module

icon set

Adding custom icon sets to the social media module

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:


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

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.


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

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.

image by webtreats

Related Posts

Optimize Social Connections Through Module Development and APIs

Brent Bice
Read more

Aggregate Your Social Media Feeds in Drupal

Rachel
Read more

Own your social media presence

Tom McCracken
Read more

Social Media ROI and How To Improve It

Felipa Villegas
Read more

Social Media 201

Sumeeta Kumar
Read more

Social Media Ethics - Where Do You Stand?

Colin
Read more