Upgrade Your Drupal Skills

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

See Advanced Courses NAH, I know Enough

The must-have Drupal module Social Sharing

Parent Feed: 

Introduction

Sending photos, videos, product recommendations, and website links to friends with social networking accounts are all firmly embedded in our lives. It is clear that progress cannot be stopped and social networks have become routine for us. Search systems pay more and more attention to them.

In our practice, it often happens that for a commercial project we create a custom module that becomes successful and popular. This was the case with Bibliography & Citation, and we hope it will be with Social Sharing - a new module from our back-end developer of the ADCI Solutions web studio.

Here’s what he says about his module: “Most of the modules for social sharing of web pages on drupal.org - are Drupal blocks that have these social media by default. You can not easily add any social service that you want to your site.

I developed a fundamentally different module for these purposes on one of the projects. Its name is Social Sharing - that's the best way to call it”. On behalf of our developer, we will tell the story of how the module was created.

Historical data

Тhere is a moment that has become critical for our client in the work of the well-known service for sharing web pages on the social network AddToAny.

The usual Twitter share URL looks like that:

https://twitter.com/intent/tweet?text=Hello%20world

And here is the sharing of the same page, but via AddToAny:

https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.addtoa...

At first, we see that the request is going through AddToAny, then it is processed and only then shared on Twitter. The shared content is meant to be public by default, but the client didn't want the traffic to go elsewhere.

We needed something flexible and custom. I made an MVP of such a module for a client and rolled out a modified version of Social Sharing on drupal.org. About 20% of the module that I used on the project remained in Social Sharing - only one basic idea. What's changed is:

  • A custom plugin type was redesigned. This plugin is responsible for social media;
  • The custom field type that was used on the project, and its components (widget and formatter) were redesigned. Now the share URL is dynamic and can be changed for each node;
  • A new block type with social media services was created;
  • I added an extra field with its settings (for which entities will be used and which services are available);
  • The views-field was created;
  • The most relevant feature was developed - supporting of the tokens for sharing URL that allows content to be shared from any field of the node;
  • 25 new services were created for sharing: Blogger, Diaspora, Douban, Evernote, Flipboard, Getpocket, Gmail, Google Bookmarks, Hacker News, InstaPaper, LineMe, LiveJournal, OK.RU, Pinterest, QZone, Reddit, RenRen, Skype, Telegram, Tumblr, Vk, Weibo, WhatsApp, Xing, Yahoo. These services are available out of the box after installing the module.

Some details for you are below.

Why you should choose the Social Sharing module

  1. It's flexible. The module is based on the Drupal plugin system, on which the eighth version of the CMS was built. It means that any developer will be able to add their social network for sharing if it is not used in the current version.
  2. It provides stable functionality. Other modules don't do that - I investigated the ones I found. There was the only one that was made in the same way with the plugins, but it is not practical, and I could not get it to work well. The idea was similar but not completed.
  3. It has a dynamic sharing URL and token support. Many modules allow using sharing not as a block on the page but as a field in the content. You need to add this field to any type of content to do this. Our module can do the same, but with many more opportunities. You can set the very same information that the user wants to share for each page individually: not only the title of the page with the URL but any content from this page.

The setup and operation of the Social Sharing module

Now let's talk more about the configuration of various features.

Extrafield configuration

If you need the same sharing links with the same content for different entities on the site for sharing, then you can use Extrafield. There is a separate configuration page for it, where the user can configure:

  • types of entities for which this field will be available;
  • social networks that will be available;
  • content to be shared.
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