FontAwesome.php in Social Media Links Block and Field 8.2
File
src/Plugin/SocialMediaLinks/Iconset/FontAwesome.php
View source
<?php
namespace Drupal\social_media_links\Plugin\SocialMediaLinks\Iconset;
use Drupal\social_media_links\IconsetBase;
use Drupal\social_media_links\IconsetInterface;
class FontAwesome extends IconsetBase implements IconsetInterface {
public function setPath($iconset_id) {
$this->path = $this->finder
->getPath($iconset_id) ? $this->finder
->getPath($iconset_id) : 'library';
}
public function getStyle() {
return [
'2x' => 'fa-2x',
'3x' => 'fa-3x',
'4x' => 'fa-4x',
'5x' => 'fa-5x',
'in' => 'fa-in',
'lg' => 'fa-lg',
'fw' => 'fa-fw',
];
}
public function getIconElement($platform, $style) {
$icon_name = $platform
->getIconName();
switch ($icon_name) {
case 'vimeo':
$icon_name = $icon_name . '-square';
break;
case 'googleplus':
$icon_name = 'google-plus';
break;
case 'email':
$icon_name = 'envelope';
break;
case 'website':
$icon_name = 'home';
break;
}
if ($icon_name == 'envelope' || $icon_name == 'home' || $icon_name == 'rss') {
$icon = [
'#type' => 'markup',
'#markup' => "<span class='fa fa-{$icon_name} fa-{$style}'></span>",
];
}
else {
$icon = [
'#type' => 'markup',
'#markup' => "<span class='fab fa-{$icon_name} fa-{$style}'></span>",
];
}
return $icon;
}
public function getLibrary() {
if (\Drupal::service('module_handler')
->moduleExists('fontawesome')) {
return parent::getLibrary();
}
else {
return [
'social_media_links/fontawesome.component',
];
}
}
public function getIconPath($icon_name, $style) {
return NULL;
}
}