You are here

class IndentBlock in CKEditor IndentBlock 8

Defines the "Indent Block" 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.

Plugin annotation


@CKEditorPlugin(
  id = "indentblock",
  label = @Translation("Indent Block")
)

Hierarchy

Expanded class hierarchy of IndentBlock

File

src/Plugin/CKEditorPlugin/IndentBlock.php, line 24

Namespace

Drupal\ckeditor_indentblock\Plugin\CKEditorPlugin
View source
class IndentBlock extends CKEditorPluginBase implements CKEditorPluginContextualInterface, CKEditorPluginConfigurableInterface, CKEditorPluginCssInterface {

  /**
   * {@inheritdoc}
   */
  public function getCssFiles(Editor $editor) {
    return [
      drupal_get_path('module', 'ckeditor_indentblock') . '/css/plugins/indentblock/ckeditor.indentblock.css',
    ];
  }

  /**
   * {@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() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    $library_url = $this
      ->getLibraryURL();
    if ($library_url != '') {
      return $library_url;
    }
    else {

      // Default value, if CKEditor Indentblock library is not found.
      return 'libraries/indentblock/plugin.js';
    }
  }

  /**
   * {@inheritdoc}
   */
  public function isEnabled(Editor $editor) {

    // Enable this plugin, if it is configured as being enabled and at least one
    // of the buttons, Indent or Outdent, is enabled.
    $settings = $editor
      ->getSettings();
    if (isset($settings['plugins']['indentblock']) && $settings['plugins']['indentblock']['enable']) {
      foreach ($settings['toolbar']['rows'] as $row) {
        foreach ($row as $group) {
          foreach ($group['items'] as $button) {
            if ($button === 'Indent' || $button === 'Outdent') {
              return TRUE;
            }
          }
        }
      }
    }
    return FALSE;
  }

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

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

    // The Indent plugin is internal for Drupal 8 CKEditor and thus can't be
    // defined as a dependency.
    return [];
  }

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

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return [
      'indentClasses' => [
        'Indent1',
        'Indent2',
        'Indent3',
        'Indent4',
        'Indent5',
        'Indent6',
        'Indent7',
        'Indent8',
        'Indent9',
        'Indent10',
      ],
      'indentOffset' => 2,
      'indentUnit' => 'em',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
    $settings = $editor
      ->getSettings();
    $form['enable'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable indentation on paragraphs'),
      '#default_value' => !empty($settings['plugins']['indentblock']) && $settings['plugins']['indentblock']['enable'] === 1 ? $settings['plugins']['indentblock']['enable'] : 0,
    );
    if ($this
      ->getLibraryURL() == '') {
      $form['enable']['#disabled'] = TRUE;
      $form['enable']['#description'] = $this
        ->t('CKEditor IndentBlock cannot be enabled, as the plugin has not been found in any libraries path!');
      $form['enable']['#default_value'] = 0;
    }
    return $form;
  }

  /**
   * Get the CKEditor Indentblock library URL.
   */
  protected function getLibraryURL() {

    // Search for the path under the current site for multisites.
    $directories[] = \Drupal::service('site.path') . "/libraries/";

    // Search also the root 'libraries' directory.
    $directories[] = 'libraries/';

    // Search also at the path for ckeditor plugins.
    $directories[] = 'libraries/ckeditor/plugins/';

    // Installation profiles can place libraries into a 'libraries' directory,
    // so search that too.
    if ($installProfile = \Drupal::installProfile()) {
      $profile_path = drupal_get_path('profile', $installProfile);
      $directories[] = "{$profile_path}/libraries/";
    }
    foreach ($directories as $dir) {
      if (file_exists(DRUPAL_ROOT . '/' . $dir . 'indentblock/plugin.js')) {
        return $dir . 'indentblock/plugin.js';
      }
    }

    // CKEditor Indentblock library not found.
    return '';
  }

}

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
IndentBlock::getButtons public function 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. Overrides CKEditorPluginButtonsInterface::getButtons
IndentBlock::getConfig public function Returns the additions to CKEDITOR.config for a specific CKEditor instance. Overrides CKEditorPluginInterface::getConfig
IndentBlock::getCssFiles public function Retrieves enabled plugins' iframe instance CSS files. Overrides CKEditorPluginCssInterface::getCssFiles
IndentBlock::getDependencies public function Returns a list of plugins this plugin requires. Overrides CKEditorPluginBase::getDependencies
IndentBlock::getFile public function Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface::getFile
IndentBlock::getLibraries public function Returns a list of libraries this plugin requires. Overrides CKEditorPluginBase::getLibraries
IndentBlock::getLibraryURL protected function Get the CKEditor Indentblock library URL.
IndentBlock::isEnabled public function Checks if this plugin should be enabled based on the editor configuration. Overrides CKEditorPluginContextualInterface::isEnabled
IndentBlock::isInternal public function Indicates if this plugin is part of the optimized CKEditor build. Overrides CKEditorPluginBase::isInternal
IndentBlock::settingsForm public function Returns a settings form to configure this CKEditor plugin. Overrides CKEditorPluginConfigurableInterface::settingsForm
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.
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.