This module is meant to make it easier for you to add cool social media links to your organisation - right on your Drupal Website!
Clone the repository to your system, and copy the files into your Drupal Installation at \modules\custom\sociallinks\
.
Navigate to Manage → Extend → Custom
and check SocialLinks
.
Click on Install. You are now ready to start using SocialLinks.
You can configure the module to specify the URLs for the social media links in the grid.
Note: You must be an administrator for this.
Navigate to Manage → Configuration → Development → SocialLinks Configuration
This will lead you to /admin/config/Social/config
.
In each text field, enter the required value (usually username) for each corresponding website.
Click on Save Configuration. You are done!
Head on to /Social
from your website to see SocialLinks in action.
For a working demo, click here.
SocialLinks was made entirely by me, and the only external library I used was FontAwesome for the Social Media Website Icons.
https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css
I followed some Drupal 8 Module Tutorials from the following links, to get acquainted with Drupal (as I never worked on it before) to get a start.
For reference to a simple working model to understand the skeleton of a module, I referred to Sidharrell's D8HW Example.
The module consists of the basic .info.yml
to provide information about the module while installing it, .links.menu.yml
to specify the path to be linked from Configuration section of admin pages, and a .routing.yml
to specify what should be displayed at which path (the content and the settings) and for whom.
One of the problems I experienced was that the link for SocialLinks Configuration in Configuration page was taking me to
/Social
where the module's content lives, not the settings - even though I had specified/admin/config/Social/config
in.routing.yml
.The problem was finally solved when I changed
route_name
undersociallinks.admin
tosociallinks.config
(which is routed to configuration), which I had mistakenly put tosociallinks.content
(which routes to the content page).
Further, there is a GNU LICENSE
and README.md
needed for the Git repository.
The module consists of 2 components - a controller (sociallinksController
) and a form (sociallinksConfigForm
).
The Controller contains the markup that is returned to the page. This included the HTML
markup that makes the icons and the hyperlinks, and some CSS
within <style></style>
and a link to the FontAwesome
library. This code was taken from a fiddle I created myself at JSFiddle earlier.
The Form consists of the Configuration Form that allows Administrators to customize the links to be displayed. It has fields for each social media website and finally a submitForm()
function.
The problem I faced in this was to use the Configuration Settings Given in the Form within my Controller, to alter the markup according to the settings.
I firstly used
\Drupal::config('sociallinks.facebook')->get('sociallinks.facebook')
(for the value to facebook)
but this returned nothing. I noticed that I hadn't imported the required modules from Drupal Core.
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
This didn't work either and it finally did when I changed the above segment to
\Drupal::config('sociallinks.settings')->get('sociallinks.facebook')
Finally, there is a .config.yml
at config → install
to put some conventional default configuration.