AutoEmbed.php in CKEditor Media Embed Plugin 8
File
src/Plugin/CKEditorPlugin/AutoEmbed.php
View source
<?php
namespace Drupal\ckeditor_media_embed\Plugin\CKEditorPlugin;
use Drupal\ckeditor_media_embed\AssetManager;
use Drupal\ckeditor_media_embed\CKEditorVersionAwarePluginBase;
use Drupal\editor\Entity\Editor;
use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
use Drupal\ckeditor\CKEditorPluginContextualInterface;
use Drupal\Core\Form\FormStateInterface;
class AutoEmbed extends CKEditorVersionAwarePluginBase implements CKEditorPluginConfigurableInterface, CKEditorPluginContextualInterface {
public function getDependencies(Editor $editor) {
$settings = $editor
->getSettings();
$dependencies = [
'autolink',
'embedbase',
'notificationaggregator',
'notification',
];
if ($this
->needsTextMatchDependency()) {
$dependencies[] = 'textmatch';
}
if ($embed_plugin = $settings['plugins']['autoembed']['status']) {
$dependencies[] = $embed_plugin;
}
return $dependencies;
}
public function needsTextMatchDependency() {
return $this
->versionCompare('4.11') >= 0;
}
public function getLibraries(Editor $editor) {
return [];
}
public function isInternal() {
return FALSE;
}
public function getFile() {
return AssetManager::getCKEditorLibraryPluginPath() . $this
->getPluginId() . '/plugin.js';
}
public function getConfig(Editor $editor) {
return [];
}
public function isEnabled(Editor $editor) {
$settings = $editor
->getSettings();
return isset($settings['plugins']['autoembed']['status']) && (bool) $settings['plugins']['autoembed']['status'];
}
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = $editor
->getSettings();
$form['status'] = [
'#type' => 'radios',
'#title' => $this
->t('Enable auto embed'),
'#options' => [
'' => $this
->t('Disabled'),
'embed' => $this
->t('Media Embed'),
'embedsemantic' => $this
->t('Semantic Media Embed'),
],
'#default_value' => !empty($settings['plugins']['autoembed']['status']) ? $settings['plugins']['autoembed']['status'] : '',
'#description' => $this
->t('When enabled to a Media embed plugin, media resource URLs pasted into the editing area are turned into an embed resource using the selected plugin.'),
];
return $form;
}
}