You are here

abstract class IconsetBase in Social Media Links Block and Field 8.2

Base class for iconset.

Hierarchy

Expanded class hierarchy of IconsetBase

5 files declare their use of IconsetBase
ElegantThemes.php in src/Plugin/SocialMediaLinks/Iconset/ElegantThemes.php
FontAwesome.php in src/Plugin/SocialMediaLinks/Iconset/FontAwesome.php
Nouveller.php in src/Plugin/SocialMediaLinks/Iconset/Nouveller.php
SocialMediaLinksBlock.php in src/Plugin/Block/SocialMediaLinksBlock.php
SocialMediaLinksFieldDefaultFormatter.php in modules/social_media_links_field/src/Plugin/Field/FieldFormatter/SocialMediaLinksFieldDefaultFormatter.php

File

src/IconsetBase.php, line 12

Namespace

Drupal\social_media_links
View source
abstract class IconsetBase extends PluginBase implements IconsetInterface, ContainerFactoryPluginInterface {

  /**
   * {@inheritdoc}
   */
  protected $path = '';

  /**
   * {@inheritdoc}
   */
  protected $finder;

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return $this->pluginDefinition['name'];
  }

  /**
   * {@inheritdoc}
   */
  public function getPublisher() {
    return $this->pluginDefinition['publisher'];
  }

  /**
   * {@inheritdoc}
   */
  public function getPublisherUrl() {
    return $this->pluginDefinition['publisherUrl'];
  }

  /**
   * {@inheritdoc}
   */
  public function getDownloadUrl() {
    return $this->pluginDefinition['downloadUrl'];
  }

  /**
   * Get the path to the iconset.
   *
   * @return string
   *   The path.
   */
  public function getPath() {
    return $this->path;
  }

  /**
   * Set the path for the given iconset.
   *
   * @param string $iconset_id
   *   The id of the iconset.
   */
  public function setPath($iconset_id) {
    $this->path = $this->finder
      ->getPath($iconset_id);
  }

  /**
   * Get the library.
   *
   * This method is used if the iconset should be used via the Library API.
   *
   * @return array
   *   The library.
   */
  public function getLibrary() {
    return NULL;
  }

  /**
   * Get the iconset element.
   *
   * @param string $platform
   *   The platform id.
   * @param string $style
   *   The style.
   *
   * @return array
   *   The array with the icon element.
   */
  public function getIconElement($platform, $style) {
    $iconName = $platform
      ->getIconName();
    $path = $this
      ->getIconPath($iconName, $style);
    $icon = [
      '#theme' => 'image',
      '#uri' => $path,
    ];
    return $icon;
  }

  /**
   * Explode the styles.
   *
   * @param string $style
   *   The styles.
   * @param bool $key
   *   If TRUE: Only the given key is returned.
   *
   * @return string|array
   *   The array with the styles or a string if a $key was given.
   */
  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] : '',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
IconsetBase::$finder protected property
IconsetBase::$path protected property
IconsetBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
IconsetBase::explodeStyle public static function Explode the styles.
IconsetBase::getDownloadUrl public function Return the url to download the iconset. Overrides IconsetInterface::getDownloadUrl
IconsetBase::getIconElement public function Get the iconset element. 1
IconsetBase::getLibrary public function Get the library. 1
IconsetBase::getName public function Return the name of the iconset. Overrides IconsetInterface::getName
IconsetBase::getPath public function Get the path to the iconset.
IconsetBase::getPublisher public function Return the name of the publisher. Overrides IconsetInterface::getPublisher
IconsetBase::getPublisherUrl public function Return the url of the publisher. Overrides IconsetInterface::getPublisherUrl
IconsetBase::setPath public function Set the path for the given iconset. 1
IconsetBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
IconsetInterface::getIconPath public function Return the path of an icon for the given platform (iconName) and style. 3
IconsetInterface::getStyle public function Return the available styles. 3
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.