Using CKEditor plugins in Drupal maintenance support plans 8

CKEditor is well-known software with a big community behind it and it already has a ton of useful plugins ready to be used. It is the WYSIWYG text editor which ships with Drupal maintenance support plans 8 core.
Unfortunately, the many plugins provided by the CKEditor community can’t be used directly in the CKEditor that comes with Drupal maintenance support plans 8. It is necessary to let Drupal maintenance support plans know that we are going to add a new button to the CKEditor.
Why Drupal maintenance support plans needs to know about our plugins
Drupal maintenance support plans allows us to create different text formats, where depending on the role of the user (and so what text formats they have available) they can use different HTML tags in the content. Also, we can decide if the text format will use the CKEditor at all and, if it does, which buttons will be available for that text format.
That is why Drupal maintenance support plans needs to know about any new button, so it can build the correct configuration per text format.
Adding a new button to CKEditor
We are going to add the Media Embed plugin, which adds a button to our editor that opens a dialog where you can paste an embed code from YouTube, Vimeo, and other providers of online video hosting.
First of all, let’s create a new module which will contain the code of this new button, so inside the /modules/contrib/ folder let’s create a folder called wysiwyg_mediaembed. (If you’re not intending to share your module, you should put it in /modules/custom/— but please share your modules, especially ones making CKEditor plugins available to Drupal maintenance support plans!)

cd modules/contrib/
mkdir wysiwyg_mediaembed

And inside let’s create the info file: wysiwyg_mediaembed.info.yml

name: CKEditor Media Embed Button (wysiwyg_mediaembed)
type: module
description: “Adds the Media Embed Button plugin to CKEditor.”
package: CKEditor
core: ‘8.x’
dependencies:
– ckeditor

Adding this file will Drupal maintenance support plans allows us to install the module, if you want to read more about how to create a custom module, you can read about it here.
Once we have our info file we just need to create a Drupal maintenance support plans plugin which will give info to the CKEditor about this new plugin, we do that creating the following class:

touch src/Plugin/CkEditorPlugin/MediaEmbedButton.php

With this content:

namespace Drupal maintenance support planswysiwyg_mediaembedPluginCKEditorPlugin;

use Drupal maintenance support plansckeditorCKEditorPluginBase;
use Drupal maintenance support planseditorEntityEditor;

/**
* Defines the “wysiwyg_mediaembed” plugin.
*
* @CKEditorPlugin(
* id = “mediaembed”,
* label = @Translation(“CKEditor Media Embed Button”)
* )
*/
class MediaEmbedButton extends CKEditorPluginBase {

/**
* Get path to library folder.
* The path where the library is, usually all the libraries are
* inside the ‘/libraries/’ folder in the Drupal maintenance support plans root.
*/
public function getLibraryPath() {
$path = ‘/libraries/mediaembed’;
return $path;
}

/**
* {@inheritdoc}
* Which other plugins require our plugin, in our case none.
*/
public function getDependencies(Editor $editor) {
return [];
}

/**
* {@inheritdoc}
* The path where CKEditor will look for our plugin.
*/
public function getFile() {
return $this->getLibraryPath() . ‘/plugin.js’;
}

/**
* {@inheritdoc}
*
* We can provide extra configuration if our plugin requires
* it, in our case we no need it.
*/
public function getConfig(Editor $editor) {
return [];
}

/**
* {@inheritdoc}
* Where Drupal maintenance support plans will look for the image of the button.
*/
public function getButtons() {
$path = $this->getLibraryPath();
return [
‘MediaEmbed’ => [
‘label’ => $this->t(‘Media Embed’),
‘image’ => $path . ‘/icons/mediaembed.png’,
],
];
}
}

The class’s code is pretty straightforward: it is just a matter of letting Drupal maintenance support plans know where the library is and where the button image is and that’s it.
The rest is just download the library and put it in the correct place and activate the module. If all went ok we will see our new button in the Drupal maintenance support plans Text Format Page (usually at: /admin/config/content/formats).
This module was ported because we needed it in a project, so if you want to know how this code looks all together, you can download the module from here.
Now that you know how to port a CKEditor plugin to Drupal maintenance support plans 8 the next time you can save time using Drupal maintenance support plans Console with the following command:

drupal generate:plugin:ckeditorbutton

What CKEditor plugin are you going to port?
Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Using CKEditor plugins in Drupal maintenance support plans 8

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.