InsertView.php in Advanced Insert View 8
File
src/Plugin/CKEditorPlugin/InsertView.php
View source
<?php
namespace Drupal\insert_view_adv\Plugin\CKEditorPlugin;
use Drupal\ckeditor\CKEditorPluginBase;
use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;
class InsertView extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface {
public function getFile() {
return drupal_get_path('module', 'insert_view_adv') . '/plugin/plugin.js';
}
public function getButtons() {
return [
'insert_view_adv' => [
'label' => $this
->t('Advanced insert View'),
'image' => drupal_get_path('module', 'insert_view_adv') . '/plugin/icon.png',
],
];
}
public function getConfig(Editor $editor) {
$settings = $editor
->getSettings();
if (isset($settings['plugins']['insert_view_adv'])) {
$plugin_specific_settings = $settings['plugins']['insert_view_adv'];
}
else {
$plugin_specific_settings = [
'enable_live_preview' => TRUE,
];
}
return $plugin_specific_settings;
}
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = $editor
->getSettings();
if (!empty($settings['plugins']['insert_view_adv'])) {
$plugin_specific_settings = $settings['plugins']['insert_view_adv'];
}
else {
$plugin_specific_settings = [
'enable_live_preview' => TRUE,
];
}
$form['enable_live_preview'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable live preview of the view token'),
'#description' => $this
->t('By default CKEditor displays only token with view details, if you want to see the exact results of the view leave this checkbox checked'),
'#default_value' => isset($plugin_specific_settings['enable_live_preview']) ? $plugin_specific_settings['enable_live_preview'] : TRUE,
'#return_value' => TRUE,
];
return $form;
}
public function getLibraries(Editor $editor) {
return [
'insert_view_adv/preview',
];
}
}