You are here

Templates.php in Wysiwyg API template plugin 8.2

Same filename and directory in other branches
  1. 3.0.x src/Plugin/CKEditorPlugin/Templates.php

File

src/Plugin/CKEditorPlugin/Templates.php
View source
<?php

namespace Drupal\wysiwyg_template\Plugin\CKEditorPlugin;

use Drupal\ckeditor\CKEditorPluginInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\editor\Entity\Editor;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Defines the CKEditor Templates plugin.
 *
 * No buttons are exposed for this plugin, it is only here so it gets properly
 * loaded by the Drupal-specific TemplateSelector plugin.
 *
 * @CKEditorPlugin(
 *   id = "templates",
 *   label = @Translation("Template selector"),
 *   module = "wysiwyg_template"
 * )
 */
class Templates extends PluginBase implements CKEditorPluginInterface, ContainerFactoryPluginInterface {

  /**
   * The wysiwyg_template.settings config object.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * The current request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * Constructs the CKEditor Templates plugin.
   *
   * @param array $configuration
   *   The plugin configuration.
   * @param string $plugin_id
   *   The plugin ID.
   * @param mixed $plugin_definition
   *   The plugin definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The current request stack.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, RequestStack $request_stack) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->config = $config_factory
      ->get('wysiwyg_template.settings');
    $this->requestStack = $request_stack;
  }

  /**
   * {@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'), $container
      ->get('request_stack'));
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() : bool {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getDependencies(Editor $editor) : array {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) : array {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() : string {
    return $this->config
      ->get('library_path') . '/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) : array {
    return [];
  }

}

Classes

Namesort descending Description
Templates Defines the CKEditor Templates plugin.