View source
<?php
namespace Drupal\social_media_links;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class IconsetBase extends PluginBase implements IconsetInterface, ContainerFactoryPluginInterface {
protected $path = '';
protected $finder;
public function __construct(array $configuration, $plugin_id, $plugin_definition, IconsetFinderService $finder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->finder = $finder;
$this
->setPath($plugin_id);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('social_media_links.finder'));
}
public function getName() {
return $this->pluginDefinition['name'];
}
public function getPublisher() {
return $this->pluginDefinition['publisher'];
}
public function getPublisherUrl() {
return $this->pluginDefinition['publisherUrl'];
}
public function getDownloadUrl() {
return $this->pluginDefinition['downloadUrl'];
}
public function getPath() {
return $this->path;
}
public function setPath($iconset_id) {
$this->path = $this->finder
->getPath($iconset_id);
}
public function getLibrary() {
return NULL;
}
public function getIconElement($platform, $style) {
$iconName = $platform
->getIconName();
$path = $this
->getIconPath($iconName, $style);
$icon = [
'#theme' => 'image',
'#uri' => $path,
];
return $icon;
}
public static function explodeStyle($style, $key = FALSE) {
$exploded = explode(':', $style);
if ($key) {
return $exploded[$key];
}
return [
'iconset' => isset($exploded[0]) ? $exploded[0] : '',
'style' => isset($exploded[1]) ? $exploded[1] : '',
];
}
}