class ScaytCKEditorButton in CKEditor SpellCheckAsYouType (SCAYT) 8
Defines the "scayt" 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 = "scayt",
label = @Translation("SCAYT spellchecker")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\ckeditor_scayt\Plugin\CKEditorPlugin\ScaytCKEditorButton implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface, ContainerFactoryPluginInterface
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ScaytCKEditorButton
File
- src/
Plugin/ CKEditorPlugin/ ScaytCKEditorButton.php, line 27
Namespace
Drupal\ckeditor_scayt\Plugin\CKEditorPluginView source
class ScaytCKEditorButton extends CKEditorPluginBase implements ContainerFactoryPluginInterface, CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface {
/**
* Stores the configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Stores the configuration for the current module.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configModule;
/**
* The library discovery service.
*
* @var \Drupal\Core\Asset\LibraryDiscoveryInterface
*/
protected $libraryDiscovery;
/**
* Constructs a \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal 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 factory for configuration objects.
* @param Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery
* The library discovery interface.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LibraryDiscoveryInterface $library_discovery) {
$this->configFactory = $config_factory;
$this->configModule = $this->configFactory
->getEditable('ckeditor_scayt.config');
$this->libraryDiscovery = $library_discovery;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* Creates an instance of the plugin.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container to pull out services used in the plugin.
* @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.
*
* @return static
* Returns an instance of this plugin.
*/
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('library.discovery'));
}
/**
* {@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.
$version = $this
->getCkEditorVersion();
$path = drupal_get_path('module', 'ckeditor_scayt') . '/dist/scayt/' . $version;
return [
'Scayt' => [
'label' => $this
->t('SCAYT spellchecker'),
'image' => $path . '/icons/scayt.png',
],
];
}
/**
* {@inheritdoc}
*/
public function getFile() {
return $this
->getLibraryPath() . '/plugin.js';
}
/**
* {@inheritdoc}
*/
public function isInternal() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getDependencies(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
public function getLibraryPath() {
$version = $this
->getCkEditorVersion();
return drupal_get_path('module', 'ckeditor_scayt') . '/dist/scayt/' . $version;
}
/**
* Returns current version of CKEditor.
*
* @return string
* CKEditor version (either 4.13, 4.14 or 4.15 (for any other version)).
*/
public function getCkEditorVersion() {
$library = $this->libraryDiscovery
->getLibraryByName('core', 'ckeditor');
$version = $library['js'][0]['version'];
$pluginVersion = strpos($version, '4.13') !== FALSE ? '4.13' : (strpos($version, '4.14') !== FALSE ? '4.14' : '4.15');
return $pluginVersion;
}
/**
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
// Defaults that provide expected basic behavior.
// Doc: https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-scayt_disableOptionsStorage.
$config = [
'scayt_autoStartup' => TRUE,
'scayt_sLang' => 'en_GB',
'scayt_disableOptionsStorage' => [
'all',
],
];
$settings = $editor
->getSettings();
if (isset($settings['plugins']['scayt'])) {
$config = $settings['plugins']['scayt'] + $config;
if (isset($config['scayt_disableOptionsStorage']) && is_string($config['scayt_disableOptionsStorage'])) {
if (empty(trim($config['scayt_disableOptionsStorage']))) {
unset($config['scayt_disableOptionsStorage']);
}
else {
$config['scayt_disableOptionsStorage'] = explode(',', $config['scayt_disableOptionsStorage']);
foreach ($config['scayt_disableOptionsStorage'] as $index => $item) {
$config['scayt_disableOptionsStorage'][$index] = trim($item);
}
}
}
// Drupal form submission stores integer (0 or 1).
// It does not work without casting to boolean.
$config['scayt_autoStartup'] = (bool) $config['scayt_autoStartup'];
}
return $config;
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
// Defaults.
$config = $this
->getConfig($editor);
$form['scayt_autoStartup'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Auto startup'),
'#description' => $this
->t('Enables Grammar As You Type (GRAYT) on SCAYT startup. When enabled, this option turns on GRAYT automatically after SCAYT started.'),
'#default_value' => $config['scayt_autoStartup'],
];
// Populate language options.
$languages = $this->configModule
->get('languages');
$options = [];
foreach ($languages as $language) {
$parts = explode('|', $language);
$options[$parts[0]] = $parts[1];
}
$form['scayt_sLang'] = [
'#type' => 'select',
'#title' => $this
->t('Language'),
'#options' => $options,
'#description' => $this
->t('Sets the default spell checking language for SCAYT.'),
'#default_value' => $config['scayt_sLang'],
];
$help_text = <<<'EOT'
<p>Disables storing of SCAYT options between sessions. Option storing will be turned off after a page refresh.
The following settings can be used:</p>
<ul>
<li><code>options</code> – Disables storing of all SCAYT Ignore options.</li>
<li><code>ignore-all-caps-words</code> – Disables storing of the "Ignore All-Caps Words" option.</li>
<li><code>ignore-domain-names</code> – Disables storing of the "Ignore Domain Names" option.</li>
<li><code>ignore-words-with-mixed-cases</code> – Disables storing of the "Ignore Words with Mixed Case" option.</li>
<li><code>ignore-words-with-numbers</code> – Disables storing of the "Ignore Words with Numbers" option.</li>
<li><code>lang</code> – Disables storing of the SCAYT spell check language.</li>
<li><code>all</code> – Disables storing of all SCAYT options.</li>
</ul>
<p>You may enter multiple values with comma separated.</p>
EOT;
$form['scayt_disableOptionsStorage'] = [
'#type' => 'textfield',
'#title' => $this
->t('Disable options storage'),
'#description' => $help_text,
'#default_value' => implode(',', $config['scayt_disableOptionsStorage']),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function isEnabled(Editor $editor) {
$settings = $editor
->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
foreach ($group['items'] as $button) {
if ($button === 'Scayt') {
return TRUE;
}
}
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ScaytCKEditorButton:: |
protected | property | Stores the configuration factory. | |
ScaytCKEditorButton:: |
protected | property | Stores the configuration for the current module. | |
ScaytCKEditorButton:: |
protected | property | The library discovery service. | |
ScaytCKEditorButton:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
ScaytCKEditorButton:: |
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:: |
|
ScaytCKEditorButton:: |
public | function | Returns current version of CKEditor. | |
ScaytCKEditorButton:: |
public | function |
Returns the additions to CKEDITOR.config for a specific CKEditor instance. Overrides CKEditorPluginInterface:: |
|
ScaytCKEditorButton:: |
public | function |
Returns a list of plugins this plugin requires. Overrides CKEditorPluginBase:: |
|
ScaytCKEditorButton:: |
public | function |
Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface:: |
|
ScaytCKEditorButton:: |
public | function |
Returns a list of libraries this plugin requires. Overrides CKEditorPluginBase:: |
|
ScaytCKEditorButton:: |
public | function | ||
ScaytCKEditorButton:: |
public | function |
Checks if this plugin should be enabled based on the editor configuration. Overrides CKEditorPluginContextualInterface:: |
|
ScaytCKEditorButton:: |
public | function |
Indicates if this plugin is part of the optimized CKEditor build. Overrides CKEditorPluginBase:: |
|
ScaytCKEditorButton:: |
public | function |
Returns a settings form to configure this CKEditor plugin. Overrides CKEditorPluginConfigurableInterface:: |
|
ScaytCKEditorButton:: |
public | function |
Constructs a \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal object. Overrides PluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |