You are here

abstract class N1EDEcosystemCKEditorPlugin in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8

Defines plugin.

Plugin annotation


@CKEditorPlugin(
  id = "N1ED",
  label = @Translation("N1ED"),
  module = "n1ed"
)

Hierarchy

Expanded class hierarchy of N1EDEcosystemCKEditorPlugin

1 file declares its use of N1EDEcosystemCKEditorPlugin
n1ed.php in src/Plugin/CKEditorPlugin/n1ed.php

File

src/Plugin/N1EDEcosystemCKEditorPlugin.php, line 21

Namespace

Drupal\n1ed\Plugin
View source
abstract class N1EDEcosystemCKEditorPlugin extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface {

  /**
   * Returns plugin name.
   *
   * @return string
   *   Plugin name is a name of add-on in CKEditor terms
   */
  public abstract function getPluginName();

  /**
   * Returns module name.
   *
   * @return string
   *   Module name is a name of module in Drupal terms
   */
  public abstract function getModuleName();

  /**
   * Returns buttons list.
   *
   * @return array
   *   Associative array like in @CKEditorPlugin->getButtons
   */
  public abstract function getButtonsDef();

  /**
   * Adds controls to form using this class methods.
   */
  public abstract function addControlsToForm(&$form, $editor, $config);

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    if (!$this
      ->isInstalled()) {
      return array();
    }
    return $this
      ->getButtonsDef();
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return '/libraries/' . $this
      ->getPluginName() . '/plugin.min.js';
  }

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

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

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

  /**
   * {@inheritdoc}
   */
  public function isEnabled(Editor $editor) {
    return TRUE;
  }
  protected function getConfigParam($settings, $name, $default, $type) {
    if (isset($settings[$name]) && is_string($settings[$name]) && strlen($settings[$name]) > 0) {
      $value = $settings[$name];
    }
    else {
      $value = $default;
    }
    if (isset($type) && $type == 'number') {
      $value = intval($value);
    }
    else {
      if (isset($type) && $type == 'boolean') {
        if ($value == 'true') {
          $value = true;
        }
        else {
          if ($value == 'false') {
            $value = false;
          }
        }
      }
      else {
        if (isset($type) && $type == 'json') {
          if ($value != '') {
            $value = json_decode($value);
          }
        }
      }
    }
    $drupal8_specific_defaults = array(
      'urlFileManager' => '/flmngr',
      'urlFiles' => '/sites/default/files/flmngr',
      'dirUploads' => '/uploads/',
    );
    if (isset($drupal8_specific_defaults[$name]) && $value == '') {
      $value = $drupal8_specific_defaults[$name];
    }
    return $value;
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    $settings = array();
    if (isset($editor
      ->getSettings()['plugins'][$this
      ->getPluginName()])) {
      $settings = $editor
        ->getSettings()['plugins'][$this
        ->getPluginName()];
    }
    return $settings;
  }
  protected function addStringToForm(&$form, $settings, $param, $default) {
    $form[$param] = array(
      '#type' => 'textfield',
      '#title' => $param,
      '#title_display' => 'invisible',
      '#default_value' => $this
        ->getConfigParam($settings, $param, $default, 'string'),
      '#attributes' => array(
        'style' => 'display: none!important',
        'data-n1ed-eco-param-name' => $param,
        'data-n1ed-eco-param-type' => 'string',
        'data-n1ed-eco-param-default' => $default,
      ),
    );
  }
  protected function addNumberToForm(&$form, $settings, $param, $default) {
    $form[$param] = array(
      '#type' => 'textfield',
      '#title' => $param,
      '#title_display' => 'invisible',
      '#default_value' => $this
        ->getConfigParam($settings, $param, $default, 'number'),
      '#attributes' => array(
        'style' => 'display: none!important',
        'data-n1ed-eco-param-name' => $param,
        'data-n1ed-eco-param-type' => 'number',
        'data-n1ed-eco-param-default' => $default,
      ),
    );
  }
  protected function addBooleanToForm(&$form, $settings, $param, $default) {
    $form[$param] = array(
      '#type' => 'textfield',
      '#title' => $param,
      '#title_display' => 'invisible',
      '#default_value' => $this
        ->getConfigParam($settings, $param, $default, 'boolean') ? "true" : "false",
      '#attributes' => array(
        'style' => 'display: none!important',
        'data-n1ed-eco-param-name' => $param,
        'data-n1ed-eco-param-type' => 'boolean',
        'data-n1ed-eco-param-default' => $default ? "true" : "false",
      ),
    );
  }
  protected function addJsonToForm(&$form, $settings, $param, $default) {
    $form[$param] = array(
      '#type' => 'textarea',
      '#title' => $param,
      '#title_display' => 'invisible',
      '#default_value' => $this
        ->getConfigParam($settings, $param, $default, 'string'),
      '#attributes' => array(
        'style' => 'display: none!important',
        'data-n1ed-eco-param-name' => $param,
        'data-n1ed-eco-param-type' => 'json',
        'data-n1ed-eco-param-default' => $default,
      ),
    );
  }
  protected function isInstalled() {
    return file_exists($_SERVER['DOCUMENT_ROOT'] . '/libraries/' . $this
      ->getPluginName());
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
    $config = $this
      ->getConfig($editor);
    $form['info'] = [
      '#type' => 'html_tag',
      '#tag' => 'div',
      '#attributes' => [
        'data-n1ed-eco-plugin' => $this
          ->getPluginName(),
        'data-plugin-installed' => $this
          ->isInstalled() ? "true" : "false",
        'style' => 'display: inline-block;margin-top: 13px;margin-left: 10px;',
      ],
      '#value' => '<a href="#n1ed-conf">Configure ' . $this
        ->getPluginName() . ' add-on</a>',
    ];
    $form['#attached']['library'][] = $this
      ->getModuleName() . '/' . $this
      ->getModuleName();
    $this
      ->addControlsToForm($form, $editor, $config);
    return $form;
  }

}

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
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
N1EDEcosystemCKEditorPlugin::addBooleanToForm protected function
N1EDEcosystemCKEditorPlugin::addControlsToForm abstract public function Adds controls to form using this class methods. 1
N1EDEcosystemCKEditorPlugin::addJsonToForm protected function
N1EDEcosystemCKEditorPlugin::addNumberToForm protected function
N1EDEcosystemCKEditorPlugin::addStringToForm protected function
N1EDEcosystemCKEditorPlugin::getButtons public function Returns the buttons that this plugin provides, along with metadata. Overrides CKEditorPluginButtonsInterface::getButtons
N1EDEcosystemCKEditorPlugin::getButtonsDef abstract public function Returns buttons list. 1
N1EDEcosystemCKEditorPlugin::getConfig public function Returns the additions to CKEDITOR.config for a specific CKEditor instance. Overrides CKEditorPluginInterface::getConfig
N1EDEcosystemCKEditorPlugin::getConfigParam protected function
N1EDEcosystemCKEditorPlugin::getDependencies public function Returns a list of plugins this plugin requires. Overrides CKEditorPluginBase::getDependencies
N1EDEcosystemCKEditorPlugin::getFile public function Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface::getFile
N1EDEcosystemCKEditorPlugin::getLibraries public function Returns a list of libraries this plugin requires. Overrides CKEditorPluginBase::getLibraries
N1EDEcosystemCKEditorPlugin::getModuleName abstract public function Returns module name. 1
N1EDEcosystemCKEditorPlugin::getPluginName abstract public function Returns plugin name. 1
N1EDEcosystemCKEditorPlugin::isEnabled public function Checks if this plugin should be enabled based on the editor configuration. Overrides CKEditorPluginContextualInterface::isEnabled
N1EDEcosystemCKEditorPlugin::isInstalled protected function
N1EDEcosystemCKEditorPlugin::isInternal public function Indicates if this plugin is part of the optimized CKEditor build. Overrides CKEditorPluginBase::isInternal
N1EDEcosystemCKEditorPlugin::settingsForm public function Returns a settings form to configure this CKEditor plugin. Overrides CKEditorPluginConfigurableInterface::settingsForm
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.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 92
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.