You are here

BidiCKEditorButton.php in CKEditor BiDi Buttons 8

File

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

/**
 * @file
 * Contains \Drupal\ckeditor_bidi\Plugin\CKEditorPlugin\BidiCKEditorButton.
 */
namespace Drupal\ckeditor_bidi\Plugin\CKEditorPlugin;

use Drupal\ckeditor\CKEditorPluginBase;
use Drupal\editor\Entity\Editor;

/**
 * Defines the "bidi" plugin.
 *
 * NOTE: The plugin ID ('id' key) corresponds to the CKEditor plugin name.
 * It is the first argument of the CKEDITOR.plugins.add() function in the
 * plugin.js file.
 *
 * @CKEditorPlugin(
 *   id = "bidi",
 *   label = @Translation("Bidi CKEditor Buttons")
 * )
 */
class BidiCKEditorButton extends CKEditorPluginBase {

  /**
   * {@inheritdoc}
   *
   * NOTE: The keys of the returned array corresponds to the CKEditor button
   * names. They are the first argument of the editor.ui.addButton() or
   * editor.ui.addRichCombo() functions in the plugin.js file.
   */
  public function getButtons() {

    // Make sure that the path to the image matches the file structure of
    // the CKEditor plugin you are implementing.
    $path = 'libraries/bidi';

    // Support for "Libaraies API" module.
    if (\Drupal::moduleHandler()
      ->moduleExists('libraries')) {
      $path = libraries_get_path('bidi');
    }
    return array(
      'BidiLtr' => array(
        'label' => $this
          ->t('Text direction from left to right'),
        'image' => $path . '/icons/bidiltr.png',
      ),
      'BidiRtl' => array(
        'label' => $this
          ->t('Text direction from right to left'),
        'image' => $path . '/icons/bidirtl.png',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    $file_path = 'libraries/bidi/plugin.js';

    // Support for "Libaraies API" module.
    if (\Drupal::moduleHandler()
      ->moduleExists('libraries')) {
      $file_path = libraries_get_path('bidi') . '/plugin.js';
    }
    return $file_path;
  }

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

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

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

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

}

Classes

Namesort descending Description
BidiCKEditorButton Defines the "bidi" plugin.