You are here

abstract class StylesGroupPluginBase in Bootstrap Styles 1.0.x

A base class to help developers implement their own Styles Group plugins.

Hierarchy

Expanded class hierarchy of StylesGroupPluginBase

6 files declare their use of StylesGroupPluginBase
Animation.php in src/Plugin/BootstrapStyles/StylesGroup/Animation.php
Background.php in src/Plugin/BootstrapStyles/StylesGroup/Background.php
Border.php in src/Plugin/BootstrapStyles/StylesGroup/Border.php
Shadow.php in src/Plugin/BootstrapStyles/StylesGroup/Shadow.php
Spacing.php in src/Plugin/BootstrapStyles/StylesGroup/Spacing.php

... See full list

File

src/StylesGroup/StylesGroupPluginBase.php, line 16

Namespace

Drupal\bootstrap_styles\StylesGroup
View source
abstract class StylesGroupPluginBase extends PluginBase implements StylesGroupPluginInterface, ContainerFactoryPluginInterface {
  use StringTranslationTrait, HelperTrait;

  /**
   * Config settings.
   *
   * @var string
   */
  const CONFIG = 'bootstrap_styles.settings';

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a StylePluginBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('config.factory'));
  }

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

  /**
   * {@inheritdoc}
   */
  public function getIconPath() {

    // The default icon.
    $icon_path = drupal_get_path('module', 'bootstrap_styles') . 'images/plugin-group-default-icon.svg';
    if (isset($this->pluginDefinition['icon'])) {
      $icon = $this->pluginDefinition['icon'];
      $path_array = explode('/', $icon);
      if (isset($path_array[0])) {
        $module_name = $path_array[0];
        $icon_path = drupal_get_path('module', $module_name) . str_replace($module_name, '', $icon);
      }
    }
    return $icon_path;
  }

  /**
   * {@inheritdoc}
   */
  public function getTitleWithIcon() {
    return [
      '#markup' => $this
        ->getSvgIconMarkup($this
        ->getIconPath()),
      '#prefix' => '<span class="bs-group-title">',
      '#suffix' => $this
        ->getTitle() . '</span>',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function config() {
    return $this->configFactory
      ->getEditable(static::CONFIG);
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function buildStyleFormElements(array &$form, FormStateInterface $form_state, $storage) {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function submitStyleFormElements(array $group_elements) {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function build(array $build, array $storage, $theme_wrapper = NULL) {
    return $build;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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 2
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. 4
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.
StylesGroupPluginBase::$configFactory protected property The config factory.
StylesGroupPluginBase::build public function
StylesGroupPluginBase::buildConfigurationForm public function 6
StylesGroupPluginBase::buildStyleFormElements public function 5
StylesGroupPluginBase::config public function
StylesGroupPluginBase::CONFIG constant Config settings.
StylesGroupPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
StylesGroupPluginBase::getIconPath public function
StylesGroupPluginBase::getTitle public function Return the title of the Styles Group form plugin. Overrides StylesGroupPluginInterface::getTitle
StylesGroupPluginBase::getTitleWithIcon public function
StylesGroupPluginBase::submitConfigurationForm public function
StylesGroupPluginBase::submitStyleFormElements public function 1
StylesGroupPluginBase::validateConfigurationForm public function
StylesGroupPluginBase::__construct public function Constructs a StylePluginBase object. Overrides PluginBase::__construct