-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LIB-662 initial scifree ckeditor integration
- Loading branch information
Showing
9 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ settings: | |
items: | ||
- Wc-search | ||
- eresources | ||
- Scifree | ||
plugins: | ||
drupallink: | ||
linkit_enabled: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
div.scifree { | ||
margin: 1em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(function (CKEDITOR) { | ||
|
||
'use strict'; | ||
|
||
CKEDITOR.plugins.add('scifree', { | ||
requires: 'widget', | ||
icons: 'scifree', | ||
|
||
init: function(editor) { | ||
CKEDITOR.document.appendStyleText('.cke_button__scifree_label {display: inline;}'); | ||
|
||
editor.widgets.add('scifree', { | ||
button: 'SciFree', | ||
template: '<div class="scifree">SciFree Search Widget</div>', | ||
allowedContent: 'div(!scifree)', | ||
requiredContent: 'div(scifree)', | ||
upcast: function(element) { | ||
return element.name == 'div' && element.hasClass('scifree'); | ||
}, | ||
}); | ||
} | ||
}); | ||
})(CKEDITOR); |
72 changes: 72 additions & 0 deletions
72
custom/modules/guides/src/Plugin/CKEditorPlugin/SciFree.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Drupal\guides\Plugin\CKEditorPlugin; | ||
|
||
use Drupal\ckeditor\CKEditorPluginBase; | ||
use Drupal\ckeditor\CKEditorPluginCssInterface; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\editor\Entity\Editor; | ||
|
||
/** | ||
* Defines the "SciFree" plugin. | ||
* | ||
* @CKEditorPlugin( | ||
* id = "scifree", | ||
* label = @Translation("SciFree"), | ||
* module = "guides" | ||
* ) | ||
*/ | ||
class SciFree extends CKEditorPluginBase implements CKEditorPluginCssInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDependencies(Editor $editor) { | ||
return []; | ||
} | ||
|
||
/** | ||
* Implements \Drupal\ckeditor\Plugin\CKEditorPluginInterface::isInternal(). | ||
*/ | ||
public function isInternal() { | ||
return FALSE; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFile() { | ||
return \Drupal::service('extension.list.module')->getPath('guides') . '/js/plugins/scifree/plugin.js'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getButtons() { | ||
return [ | ||
'Scifree' => [ | ||
'label' => $this->t('SciFree'), | ||
'image' => \Drupal::service('extension.list.module')->getPath('guides') . '/js/plugins/scifree/icons/scifree.png', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConfig(Editor $editor) { | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCssFiles(Editor $editor) { | ||
return [ | ||
\Drupal::service('extension.list.module')->getPath('guides') . '/css/ckeditor-scifree.css', | ||
]; | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
custom/modules/guides/src/Plugin/Filter/FilterCKEditorSciFree.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Drupal\guides\Plugin\Filter; | ||
|
||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\Core\Render\RendererInterface; | ||
use Drupal\filter\FilterProcessResult; | ||
use Drupal\filter\Plugin\FilterBase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Provides a filter to convert sci free tags to a full widget. | ||
* | ||
* @Filter( | ||
* id = "filter_guides_ckeditor_scifree", | ||
* title = @Translation("Replace SciFree placeholder with the full widget"), | ||
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE | ||
* ) | ||
*/ | ||
class FilterCKEditorSciFree extends FilterBase implements ContainerFactoryPluginInterface { | ||
|
||
|
||
/** | ||
* The renderer. | ||
* | ||
* @var \Drupal\Core\Render\RendererInterface | ||
*/ | ||
protected $renderer; | ||
|
||
/** | ||
* Class constructor. | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
$this->renderer = $renderer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('renderer') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function settingsForm(array $form, FormStateInterface $form_state) { | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process($text, $langcode) { | ||
$result = new FilterProcessResult($text); | ||
|
||
if (strpos($text, '<div class="scifree"') !== FALSE) { | ||
$render = [ | ||
'#theme' => 'ckeditor-scifree', | ||
]; | ||
$widget = $this->renderer->render($render); | ||
$text = str_replace('<div class="scifree">SciFree Search Widget</div>', $widget, $text); | ||
$result->setProcessedText($text); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function tips($long = FALSE) { | ||
return $this->t('Replace SciFree placeholder with the full widget'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<div id="scfwid" data-account="unb"></div> | ||
<script src="https://search.scifree.se/assets/external/widget.js"></script> |