Giter VIP home page Giter VIP logo

ckeditor's Introduction

CKEditor icon

CKEditor

This plugin adds a “CKEditor” field type to Craft CMS, which provides a deeply-integrated rich text and longform content editor, powered by CKEditor 5.

A CKEditor field with example content filled in.

Table of Contents:

Requirements

This plugin requires Craft CMS 5.0.0-beta.7 or later.

Installation

You can install this plugin from the Plugin Store or with Composer.

From the Plugin Store:

Go to the Plugin Store in your project’s Control Panel and search for “CKEditor”. Then click on the “Install” button in its modal window.

With Composer:

Open your terminal and run the following commands:

# go to the project directory
cd /path/to/my-project.test

# tell Composer to load the plugin
composer require craftcms/ckeditor

# tell Craft to install the plugin
./craft plugin/install ckeditor

Configuration

CKEditor configs are managed globally from SettingsCKEditor.

Configurations define the available toolbar buttons, as well as any custom config options and CSS styles that should be regisered with the field.

New configs can also be created inline from CKEditor field settings.

A “Create a new field” page within the Craft CMS control panel, with “CKEditor” as the chosen field type. A slideout is open with CKEditor config settings.

Registering Custom Styles

CKEditor’s Styles plugin makes it easy to apply custom styles to your content via CSS classes.

You can define custom styles within CKEditor configs using the style config option:

return {
  style: {
    definitions: [
      {
        name: 'Tip',
        element: 'p',
        classes: ['note']
      },
      {
        name: 'Warning',
        element: 'p',
        classes: ['note', 'note--warning']
      },
    ]
  }
}

You can then register custom CSS styles that should be applied within the editor when those styles are selected:

.ck.ck-content p.note {
    border-left: 4px solid #4a7cf6;
    padding-left: 1rem;
    color: #4a7cf6;
}

.ck.ck-content p.note--warning {
    border-left-color: #e5422b;
    color: #e5422b;
}

HTML Purifier Configs

CKEditor fields use HTML Purifier to ensure that no malicious code makes it into its field values, to prevent XSS attacks and other vulnerabilities.

You can create custom HTML Purifier configs that will be available to your CKEditor fields. They should be created as JSON files in your config/htmlpurifier/ folder.

Use this as a starting point, which is the default config that CKEditor fields use if no custom HTML Purifier config is selected:

{
  "Attr.AllowedFrameTargets": [
    "_blank"
  ],
  "Attr.EnableID": true
}

See the HTML Purifier documentation for a list of available config options.

For advanced customization, you can modify the HTMLPurifier_Config object directly via the craft\ckeditor\Field::EVENT_MODIFY_PURIFIER_CONFIG event.

use craft\htmlfield\events\ModifyPurifierConfigEvent;
use craft\ckeditor\Field;
use HTMLPurifier_Config;
use yii\base\Event;

Event::on(
    Field::class,
    Field::EVENT_MODIFY_PURIFIER_CONFIG,
    function(ModifyPurifierConfigEvent $event) {
        /** @var HTMLPurifier_Config $config */
        $config = $event->config;
        // ...
    }
);

Embedding Media

CKEditor 5 stores references to embedded media embeds using oembed tags. Craft CMS configures HTML Purifier to support these tags, however you will need to ensure that the URI.SafeIframeRegexp HTML Purifier setting is set to allow any domains you wish to embed content from.

See CKEditor’s media embed documentation for examples of how to show the embedded media on your front end.

Longform Content with Nested Entries

CKEditor fields can be configured to manage nested entries, which will be displayed as cards within your rich text content, and edited via slideouts.

A CKEditor field with a nested entry’s slideout open.

Nested entries can be created anywhere within your content, and they can be moved, copied, and deleted, just like images and embedded media.

Setup

To configure a CKEditor field to manage nested entries, follow these steps:

  1. Go to SettingsFields and click on your CKEditor field’s name (or create a new one).
  2. Double-click on the selected CKEditor config to open its settings.
  3. Drag the “New entry” menu button into the toolbar, and save the CKEditor config.
  4. Back on the field’s settings, select one or more entry types which should be available within CKEditor fields.
  5. Save the field’s settings.

Now the field is set up to manage nested entries! The next time you edit an element with that CKEditor field, the “New entry” menu button will be shown in the toolbar, and when you choose an entry type from it, a slideout will open where you can enter content for the nested entry.

An entry card will appear within the rich text content after you press Save within the slideout. The card can be moved via drag-n-drop or cut/paste from there.

You can also copy/paste the card to duplicate the nested entry.

To delete the nested entry, simply select it and press the Delete key.

Note

Copy/pasting entry cards across separate CKEditor fields is not supported.

Rendering Nested Entries on the Front End

On the front end, nested entries will be rendered automatically via their partial templates.

For each entry type selected by your CKEditor field, create a _partials/entry/<entryTypeHandle>.twig file within your templates/ folder, and place your template code for the entry type within it.

An entry variable will be available to the template, which references the entry being rendered.

Tip

If your nested entries contain any relation fields, you can eager-load their related elements for each of the CKEditor field’s nested entries using eagerly().

{% for image in entry.myAssetsField.eagerly().all() %}

Converting Redactor Fields

You can used the ckeditor/convert command to convert any existing Redactor fields over to CKEditor. For each unique Redactor config, a new CKEditor config will be created.

php craft ckeditor/convert

Adding CKEditor Plugins

Craft CMS plugins can register additional CKEditor plugins to extend its functionality.

The first step is to create a DLL-compatible package which provides the CKEditor plugin(s) you wish to add.

💡 Check out CKEditor’s Implementing an inline widget tutorial for an in-depth look at how to create a custom CKEditor plugin.

Once the CKEditor package is in place in your Craft plugin, create an asset bundle which extends BaseCkeditorPackageAsset. The asset bundle defines the package’s build directory, filename, a list of CKEditor plugin names provided by the package, and any toolbar items that should be made available via the plugin.

For example, here’s an asset bundle which defines a “Tokens” plugin:

<?php

namespace mynamespace\web\assets\tokens;

use craft\ckeditor\web\assets\BaseCkeditorPackageAsset;

class TokensAsset extends BaseCkeditorPackageAsset
{
    public $sourcePath = __DIR__ . '/build';

    public $js = [
        'tokens.js',
    ];

    public array $pluginNames = [
        'Tokens',
    ];

    public array $toolbarItems = [
        'tokens',
    ];
}

Finally, ensure your asset bundle is registered whenever the core CKEditor asset bundle is. Add the following code to your plugin’s init() method:

\craft\ckeditor\Plugin::registerCkeditorPackage(TokensAsset::class);

ckeditor's People

Contributors

1stevengrant avatar angrybrad avatar benjamindavid avatar billythekid avatar brandonkelly avatar i-just avatar moritzlost avatar olivierbon avatar timkelty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ckeditor's Issues

CKEditor breaks existing figure elements

Description

When upgrading/converting to CKEditor, the markup for existing images with captions changes and the figure and figcaption elements get deleted.

Not sure if this is something I need to fix in HtmlPurifier, but I can embed new images in CKEditor which uses figure elements and these do persist.

Steps to reproduce

  1. In a Redactor RTE field, have an existing figure element with image and caption:
<figure><img src="/uploads/shared/1200x630.png?v=1625830523#asset:74:url" alt="OG image" data-image="4ogpunopbfm4"><figcaption>Caption for this image</figcaption></figure>
  1. Run ./craft ckeditor/convert, open the new CKEditor field
  2. View source and observe the content is now:
<p>
    <img src="/uploads/shared/1200x630.png?v=1625830523#asset:74:url" alt="OG image">Caption for this image
</p>

Additional info

  • Craft version: 4.4.8
  • PHP version: 8.1
  • Database driver & version: MariaDB 10.4.27
  • CKEditor version: 3.3.0
  • HtmlPurifier config:
{
  "Attr.AllowedFrameTargets": [
    "_blank"
  ],
  "Attr.EnableID": true,
  "HTML.AllowedComments": [
    "pagebreak"
  ],
  "HTML.SafeIframe": true,
  "URI.SafeIframeRegexp": "%^(https?:)?//(www.youtube.com/embed/|www.youtube-nocookie.com/embed/|www.youtube.com/watch|player.vimeo.com/video/|fast.wistia.net/embed/)%"
}

Edit toolbar? Source mode?

[Is it|Will it be] possible to custom the options available in the toolbar? [Is there|Will there be] a source mode option to edit HTML directly? Thanks!

Issue with wordCount and Inquiry about PRO Add-ons

I noticed that the wordCount option in the plugin's configuration does not seem to be doing anything, despite appearing as an autocomplete option. I am unsure if this is due to a missing NPM package in the plugin or some other issue.

In addition, I am curious about the availability of PRO add-ons for CKEditor within this plugin. For instance, are or will the minimap and comments features be available, and if so, how's CKEditor pro add-on licensing taking care of?

Simplify the link button

Currently, the Insert Link button in the CraftCMS CKEditor plugin has two actions: the left action is to insert a custom link, and the right action is to open a dropdown to insert an entry, asset, or category.

Ideally, the button would have only one action that shows a dropdown with all available options. If this is not possible, I suggest adding an "insert a custom link" option to the dropdown so that all options are contained within it.

Composer installation gives InvalidArgumentException

I am currently running Craft CMS 3.0.0-RC13.

When I try to install ckeditor using composer require craftcms/ckeditor, I get:

 [InvalidArgumentException]
  Could not find a version of package craftcms/ckeditor matching your minimum-stability (stable). Require it with an ex
  plicit version constraint allowing its desired stability.

My Composer version is 1.6.3.

However, using composer require craftcms/ckeditor:1.0.0-beta.2 works.

Editor doesn't load on entry versions

Steps to reproduce:

  1. Create/edit current entry e.g. /admin/entries/contentPages/slug-name/
  2. Editor loads as expected.
  3. Switch to edit a previous version e.g. /admin/entries/contentPages/slug-name/versions/163
  4. Editor doesn't load and just the textarea is visable.

Versions:

  • Craft CMS 3.0.16.1
  • CKEditor 1.0.0-beta.2

CKEditor 5 beta 2

Looks like CKEditor 5 is finally reaching some significant stability. Was curious what the going thoughts are on a roadmap for Craft integration. Thanks!

CKEditor 5 v1.0.0 beta released

We consider the API to be quite stable now and we do not expect any significant API changes at this stage. Feel free to fully try out CKEditor 5’s potential and update your code to align with the recent API changes.

No image resize functionality

Description

No image resize handles are shown in the editor and config options for resize buttons don't work. Is this feature missing intentionally ?

Additional info

  • Craft version: 4.4.9
  • PHP version: 8.1

Video Embeds Stripped Out Regardless of HTML Purifier Config

Description

The Default.json config for HTML Purifier that is included on installation has the following lines, which should prevent YouTube and Vimeo video embeds from being stripped out of a CKEditor field on save, but embeds from either platform are still being stripped out.

  "HTML.SafeIframe": true,
  "URI.SafeIframeRegexp": "%^(https?:)?//(www.youtube.com/embed/|player.vimeo.com/video/)%"

I wasn't totally sure if this issue belongs here, or in the Craft starter, or with HTML Purifier itself, but for reference, I tested this with Redactor, and it wasn't an issue there, the embeds remained after save.

Steps to reproduce

  1. Do a fresh Craft install using the Quick Start Guide
  2. Install the latest version of CKEditor with ddev composer require craftcms/ckeditor -w && ddev exec php craft plugin/install ckeditor
  3. Keep the default installation settings, which at the time of writing includes https://cdn.ckeditor.com/ckeditor5/32.0.0/classic/ckeditor.js as the CKEditor Build URL.
  4. Create a CKEditor field and add it to a section for use (you'll need to create a new section if starting fresh). Keep the default settings, which leaves "Purify HTML" as checked, and uses the Default config.
  5. Go to the entry where the field was added, and paste in a YouTube or Vimeo URL ( I recommend this one). The editor should automatically take that and produce the iframe code that displays it as an embed within the editor.
  6. Hit "save" on the entry and see your empty field where the embed should remain.

Additional info

  • Craft version: 4.3.8.1 Solo
  • PHP version: 8.0.24
  • Database driver & version: MySQL 10.4.26
  • Plugins & versions: Just CKEditor 2.2.0

Customize the toolbar

My client is requesting optoins in the toolbar that are not there including:

change text alignment

when editing links shoudl be able to set the target i.e. target="_blank"

I can't find this in the documentation. If it's not available now, how soon? also would we lose any data by switching from ckeditor to redactor if we needed to?

Empty field outputs <p>&nbsp;</p>

ckeditor 1.0.0-beta.2
craft 3.0.1

I'm using the ckeditor and found this bug when setting a conditional to only display content if the field contains data.

      {% if entry.overview|length %}
        <h2>Asset Overview</h2>
        <div class="overview">
          {{ entry.overview }}
        </div><!-- /.overview -->
      {% endif %}

On the front end I expect nothing to display, but that doens't happen because ckeditor is outputting this

<p>&nbsp;</p>

Please advise

BaseUrl changed: Incorrect url loaded in script tag

Description

I've tried the following urls in settings but unable to load them correctly:

http://@web/js/ckeditor5-31.1.0/src/ckeditor.js
http://$DEFAULT_SITE_URL/js/ckeditor5-31.1.0/src/ckeditor.js

Steps to reproduce

  1. Set baseurl to one of the values above and save (everything is validated and saves ok)

  2. load a CKeditor instance

  3. the js file loaded will have an incorrect path

Additional info

  • Craft version: 3.7.23
  • PHP version: 8.0
  • Database driver & version:
  • Plugins & versions: CKEDITOR latest

Captura de pantalla 2021-12-14 a las 20 44 01

Captura de pantalla 2021-12-14 a las 20 43 43

Lists are missing padding when viewing in the editor

Description

Lists in CKEditor are missing padding. It seems like Tailwind reset is removing the margin and padding from all ul and ol elements in the control panel. (I'm assuming this CSS is being loaded by Craft itself but please let me know if I should be looking into my other plugins instead)

image

Steps to reproduce

  1. Create a CKEditor field that includes a list button in the toolbar
  2. Enter list items in the field

Additional info

  • Craft version: 4.4.7.1
  • PHP version: 8.0.28
  • Database driver & version: MySQL 8.0.31
  • Plugins & versions:
    • Amazon S3 2.0.3
    • CKEditor 3.1.0
    • Google UA and GTM 2.1.3
    • Mailgun 3.0.0
    • Position Fieldtype 4.0.0
    • Sentry Logger 4.1.2
    • SEO 4.1.0
    • Super Table 3.0.8.1
    • Typogrify 4.0.1

Admin Page Load Event

Please let me know if this question should be moved to the Craftcms repo. It isn't specific to the CKEditor plugin, but I found it while working on the plugin, so I entered it here.

When trying to initialize a custom build for CKEditor, I noticed that the code was being executed before the textarea fields were created (even on the window load event). I assume that Craft and a plugin (Neo) are doing a bunch of JS work as well on load to layout the page. I did hacky things to make it work. I could probably figure a semi better implementation, but it would still be fragile. Are there any better solutions than iterating over the page?

Note: I attempted to load the JS via the asset bundle (I thought maybe that would load last - No idea why it would, but I tried it).

Changes made in source mode not saved

Description

If we make changes to a ckeditor field in source mode and immediately save the entry, those changes are not taken into account.
For changes to be taken into account it's necessary to switch back to WYSIWYG and then save.

Steps to reproduce

  1. edit or create an entry
  2. switch a ckeditor field to source mode
  3. make changes to the field
  4. save

=> Changes are lost

Additional info

  • Craft version: 3.7.24
  • PHP version: 7.4.26
  • Database driver & version:
  • Plugins & versions: craftcms/ckeditor 1.1.2

I've made a small video showing the behaviour:

capture-2021-12-08_17.15.37.mp4

Text Alignment and Font Colour not saved

Description

We have a Neo field with a 'Copy' block that includes a CKeditor field.
Most changes, such as bold, italic, headings, anchors etc save, but text alignment and font colour don't save. When the entry is saved those styles are removed to a default left alignment and black text.

Additional info

  • Craft version: Pro 4.4.8
  • PHP version: 8.1.18
  • Database driver & version: 5.7.42
  • Plugins & versions:
    -- Neo: 3.7.6
    -- CKEditor: 3.2.1

Wrong headings

Description

CKEditor places wrong heading. E.g. h2 is chosen, h3 is placed.

Steps to reproduce

  1. Write some text, choose "Heading 2" option for it.
  2. Check generated code - it is in tag

    .

Additional info

  • Craft version: 4.3.8.2
  • PHP version: 8.0.8
  • Database driver & version: MySQL 5.7.34
  • Plugins & versions: CKEditor 2.2.0

Screenshot 2023-02-09 at 12 12 54

Screenshot 2023-02-09 at 12 20 03

ckeditor5 dropdown padding

Description

readable class adds extra padding to dropdowns. readable should only be applied to .ck-content

Screenshot 2023-01-31 at 3 05 40 pm

Not able to add image assets

Description

Hello,

I'm getting error when trying to upload image. It's showing empty dialog when clicking on "Browser the server" button.
image

I'm using creditor 4.9.1https://cdn.ckeditor.com/4.9.1/full/ckeditor.js

Steps to reproduce

  1. Create a field with Field type ckeditor
    image
  2. Go in entries and click on image upload icon in CKEditor
  3. Click on Browser the server button.

Additional info

  • Craft version: 4.0.0.1
  • PHP version: 8.0
  • Database driver & version: mysql 8.0.23
  • Plugins & versions: craftcms/ckeditor : ^2.0

CKE 4 dies when dragged

Description

When the plugin is set to use CKEditor 4, the field will appear to lose its value and become unresponsive when it is dragged, such as within a Matrix block. Thankfully, the source <textarea> element will have already been updated, so no content is actually lost.

Steps to reproduce

  1. Set the CKEditor build URL to https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js.
  2. Create a CKEditor field within a Matrix field.
  3. Create an entry with the Matrix field., and give it a couple blocks.
  4. Drag one of the blocks.

Likely also affects Neo and Super Table.

Additional info

  • Craft version: 3.6.12
  • PHP version: n/a
  • Database driver & version: n/a
  • Plugins & versions: CKEditor 1.0.0.1

Crashes upon saving with view source open

Description

If I select the source code option and then try to save the entry (with the source code open), the browser crashes.

Steps to reproduce

Additional info

  • Craft version:
  • PHP version:
  • Database driver & version:
  • Plugins & versions:

Fields’ isEmpty() method has been deprecated. Use isValueEmpty() instead.

Description

Deprecation error in CP. Does not appear to be plugin-related, but core.

Steps to reproduce

  1. Look in deprecation logs to find error...

Fields’ isEmpty() method has been deprecated. Use isValueEmpty() instead.

Additional info

  • Craft version: Craft Solo 3.1.24
  • PHP version: 7.1.26
  • Database driver & version: MySQL 5.7.25
  • Plugins & versions:

CKEditor 1.0.0-beta.2
Craft Commerce 2.1.3.1
Events 1.0.1
Field Manager 2.0.5
Linkit 1.1.11
SEOmatic 3.1.49
Smith 1.0.0
Sprout Active 2.0.9
Stripe for Craft Commerce 1.2.1

Stack Trace

https://pastebin.com/PrKDaADG

Table rows and columns can not be added after creation

Description

Adding a table works as expected, but if you thereafter want to add a column or row that is not possible.

It can be solved by this added to the config:

return {
  table: {
      contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
  }
}

These options do however seem very sensible to enable by default.

Additional info

  • Craft version: Craft Pro 4.4.7.1
  • PHP version: 8.2.0
  • Database driver & version: MariaDB 10.4.27
  • CKEditor versions: 3.2.0

select entries in links

Description

I would like to be able to link entries the same way we are now able to link assets

#11

Thanks!

Settings not saved to the database when adding config for 'target="_blank"' to link

Description

In the Craft CMS CKEditor plugin I added some extra configuration so that a link can open in a new window. Instead of a configuration where an absolute URL always is opening in a new tab.

Steps to reproduce

  1. Install the plugin
  2. Modify the config with the code below
  3. Try and make a link in a CK Editor field with the button 'open in new tab' enabled. After saving the entry the button is reset and not saved to the database

Config
"link": { "decorators": { "openInNewTab": { "label": "Open in a new tab", "mode": "manual" } } }

Additional info

  • Craft version: 4.4.7
  • PHP version: 8.1
  • Database driver & version: 10.5.9-MariaDB
  • Plugins & versions: 3.1.0

Using previewsInData config property for media embed gets removed by HTML Purifier

We’re trying to make use of CKEditor's media embed option for YouTube and Vimeo embeds only. For that reason we’re not looking to subscribe to a premium service such as Iframely, as suggested in the CKEditor docs.

Instead, we’ve enabled the previewsInData config option for the editor, which works, but we can’t seem to workaround HTML Purifier removing the code that this option renders instead.

When set to true, previewsInData renders an embed as the following code:

<figure class="media">
	<div data-oembed-url="https://url/">
		<iframe src="https://preview/"></iframe>
	</div>
</figure>

Instead of:

<figure class="media">
	<oembed url="https://url/"></oembed>
</figure>

For info, this is our CKEditor config:

{
  "mediaEmbed": {
    "previewsInData": true
  }
}

And this is our HTML Purifier config:

{
  "Attr.AllowedFrameTargets": [
    "_blank"
  ],
  "Attr.EnableID": true,
  "HTML.AllowedComments": [
    "pagebreak"
  ],
  "HTML.SafeIframe": true,
  "URI.SafeIframeRegexp": "%^(https?:)?//(www.youtube.com/|player.vimeo.com/|vimeo.com/)%"
}

We're using Craft CMS Pro 4.4.7.1 and CKEditor 3.2.0.

We suspect the data-oembed-url is clashing with HTML Purifier, but can’t find any way to enable this attribute. Any advice would be appreciated, thanks.

CKEditor field accessible name doesn't match visible label, and lacks contextual info

Description

See title

Steps to reproduce

  1. Create a new custom field using the CKEditor field type, and add Default Instructions
  2. Add the custom field to a field layout
  3. Go to the Edit page and inspect accessibility properties: regardless of the field name, the .ck-editor__editable element has the accessible name “Editor editing area: main” and doesn’t reference instructions, errors, etc., as other fields do.

Expected behavior

  • The accessible name of the field should include the visible field name, preferably at the beginning. For example, if the field name is “Post Content,” the accessible name can be “Post Content, Editor editing area: main.”
  • Additional information, like errors and instructions, should be referenced using aria-describedby

Additional info

  • Craft version: 4.4.7
  • PHP version: 8.0.21
  • Database driver & version: MariaDB 10.4.25
  • Plugins & versions: 3.0.0

Can not add image assets

Hello,
love the implementation so far, except that there is no way to add image assets in the CP in Craft 3 after installing the plugin. I can’t find any information on how to make it work with Craft’s asset configuration and the official CKEditor documentation is quite rocket-science to me when it comes to enabling basic image functionality.
Any hints?

No initialisation when used in a matrix

Description

I have a CKeditor field inside a matrix. When I make a new entry, and add the block with the CKeditor field inside, it just shows an unstyled textarea, there is no initialisation. It does work fine when the entry gets saved and reloaded.

Additional info

  • Craft version: 3.7 beta 2
  • PHP version: 7.4

Is this plugin officially abandoned?

The last release was in January 2018, even though there are commits through march this year. We do actually make use of this. Should we be migrating away from it?

Few things

Hey :)

1. Dont see how is posiblle for links to Open in new window

2. New image transform is great, but when i add other image options in config, transform do not show

I think all this option would be great by deafult..
"image": { "toolbar": [ "imageStyle:inline", "imageStyle:wrapText", "imageStyle:breakText", "|", "toggleImageCaption", "imageTextAlternative"

3. Is it posiblle to add all table options by deafult. Tableproperties, Cellproperties

Snag_5366dee0
Tableproperties, Cellproperties

4. How to add for example Template button. .

Snag_5368f164

Thx

Additional info

  • Craft version: Craft Pro 4.4.11

  • Plugins & versions: CKEditor | 3.4.0

Content of CKEditor plugin in Craft 3.4.9 is not saved

Description

We are using craftcms/ckeditor 1.0.0-beta.2 with Craft 3.4.9 and any content of CKEditor does not get saved.

Steps to reproduce

  1. Have Craft 3.4.9 with a field of CKEditor (normal or Matrix)
  2. Have a section using that field
  3. Create an entry and enter content into the CKEditor field
  4. Save it (best by hitting Cmd+S as you will see the problem immediately)

Have a look at the content of that field again. It is empty. If something was in the field from earlier Craft Version, it will not be overwritten but stays there.

Additional info

  • Craft version: 3.4.9
  • PHP version: 7.2
  • Plugins & versions: craftcms/ckeditor (1.0.0-beta.2)

Conditionaly load plugins based on toolbar options

Description

Currently, it is possible for a CMS editor to use CKEditor features that perhaps the developer had intended. This is because even if an item isn't present in the toolbar it doesn't mean you can't use that feature and can still use other editor functionality to include certain formatting or content.

For example:

  • Even if the toolbar doesn't include the Insert image or Insert media buttons the user can still paste an image from the clipboard or an URL to an image (which CKEditor will then inline)
  • If text formatting options aren't included an editor can still use autoformatting to make text bold etc https://ckeditor.com/docs/ckeditor5/latest/features/autoformat.html

I think this is because of the way this plugin loads all of its plugins upfront.

plugins: [
Alignment,
AutoImage,
AutoLink,
Autoformat,
BlockQuote,
Bold,
Code,
CodeBlock,
Essentials,
FindAndReplace,
GeneralHtmlSupport,
Heading,
HorizontalLine,
HtmlComment,
HtmlEmbed,
Image,
ImageCaption,
ImageStyle,
ImageToolbar,
Indent,
Italic,
LinkEditing,
LinkImage,
List,
MediaEmbed,
MediaEmbedToolbar,
PageBreak,
Paragraph,
PasteFromOffice,
SelectAll,
SourceEditing,
Strikethrough,
Style,
Subscript,
Superscript,
Table,
TableCaption,
TableToolbar,
TodoList,
Underline,
WordCount,
CraftImageInsertUI,
CraftLinkUI,
],

According to the CKEditor docs things like autoformatting will only work if a related plugin is included e.g. the ** autoformatting short for bold will only work if the Bold plugin is loaded.

Would it be possible to conditionally add/remove plugins at runtime based on the toolbar items included?

We can manually remove plugins by passing in a custom config but it would be more intuitive if the available features followed the toolbar.

return {
  removePlugins: [
    'AutoImage',
    'BlockQuote',
    'Code',
    'CodeBlock',
    'Heading',
    'HorizontalLine',
    'MediaEmbed',
    'TodoList',
    'Underline',
  ],
}

Additional info

  • Craft version: 4.4
  • CKEditor: 3.0

[4.x]: Changes are not saved in CKEditor field while in "source" mode.

What happened?

Description

Changes are not saved in CKEditor field while in "source" mode.

Steps to reproduce

  1. Go to an entry and edit the contents of a CKEditor field in "source" editing mode.
  2. Save the entry

Expected behavior

The changes should be saved.

Actual behavior

The changes are lost.

If you switch back to "normal" editing mode before saving, the changes are saved.

Craft CMS version

Craft CMS 4.4.7.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

CKEditor 3.2.0

Broken bullets

When I try to make bullets, the actual bullets don't appear, and the text doesn't get indented.

You can see the video here:

https://www.screencast.com/t/lSVzrCfnS

The CKE field is inside of a Matrix field, but I'm not sure if that really makes a difference.

Fields with links and `&nbsp;` get marked as modified on focus.

Description

See #85

Steps to reproduce

  1. Create a CKEditor field and add it to an entry type.
  2. Go to an entry and add a link or a &nbsp; entity (eg by hitting ENTER twice, which creates an empty paragraph).
  3. Save the entry.
  4. Click in the field, withour typing anything.
  5. The field appears dirty.

Additional info

  • Craft version: 4.4.8
  • PHP version:
  • Database driver & version:
  • Plugins & versions: CKEditor 3.2.1

CKEditor config addTargetToExternalLinks doesn't look for internal links.

Description

When adding this option the expected behaviour would be that only external links get the target="blank" attribute, however, all links get it.

Config:

return {
  link: {
    addTargetToExternalLinks: true,
  },
}

Workaround is to set targets manually, using this config:

return {
  "link": {
    "decorators": {
      "openInNewTab": {
        "attributes": {
          "target": "_blank"
        },
        "label": "Open in a new tab",
        "mode": "manual"
      }
    }
  }
}

How to apply custom CSS to an editor?

Based on what it says here, I'm trying to apply custom styles to the editor (for a specific field). I have this line in the "Initialization Code" field for the CKEditor field in question:

import '/assets/css/ckeditor.css';

When I load that field (say, in an entry editing screen), CKEditor fails to initialize, and I get this console error:

VM4946:2 Uncaught SyntaxError: Cannot use import statement outside a module
    at m (jquery.js:133)
    at Oe (jquery.js:6114)
    at b.fn.init.append (jquery.js:6250)
    at s.constructor.initUi (main.js?v=1623931468:13)
    at s.constructor.addBlock (main.js?v=1623931468:13)
    at s.constructor.init (main.js?v=1623931468:12)
    at s.constructor.constructor (garnish.js:764)
    at s.constructor (garnish.js:40)
    at new s.constructor (garnish.js:40)
    at Object.createInput (main.js?v=1623931468:1)

I'm a humble HTML & CSS dev, and my JS is weaksauce. What am I doing wrong? And why is it so complicated? 😖

Custom heading options classes being stripped on save unless style definitions exist

Description

Using a custom config, if I set a custom heading option ("subtitle" in this example), the view class I set is being stripped on entry save. Disabling or enabling the "Purity HTML" option on the field has no effect.

heading-alone.mp4

Oddly, if I create a style definition and add the style selection option to the toolbar, the classes persist on save as expected (for both the heading option alone, and a paragraph set to the subtitle style.

heading-with-style.mp4

Config is as follows:

return {
	heading: {
		options: [
			{
				model: 'subtitle',
				view: {
					name: 'p',
					classes: 'ck-heading_subtitle'
				},
				title: 'Subtitle',
				class: 'ck-heading_subtitle'
			},
			{ model: 'heading1', view: 'h1', title: 'Large Heading', class: 'ck-heading_heading1' },
			{ model: 'heading2', view: 'h2', title: 'Small Heading', class: 'ck-heading_heading2' },
			{ model: 'paragraph', view: 'p', title: 'Paragraph', class: 'ck-heading_paragraph' },
		]
	},
	style: {
		definitions: [
			{
				name: 'Subtitle',
				element: 'p',
				classes: [ 'ck-heading_subtitle' ]
			},
		],
	}
}

I would like Subtitle to be a heading option, not a styling option, but have its class persist on save. Am I misunderstanding how to configure CKeditor, or is this a bug?

Steps to reproduce

  1. Create a custom heading option with a view object containing classes
  2. Apply heading option in rich text editor field and save

Additional info

  • Craft version: 4.4.8
  • PHP version: 8.1.13
  • Database driver & version: MariaDB 10.4.27
  • Plugins & versions: CKEditor 3.2.1
"craftcms/ckeditor": "^3.2",
"craftcms/cms": "^4.4.0",
"doublesecretagency/craft-cpcss": "^2.6",
"mmikkel/retcon": "^2.6",
"nystudio107/craft-imageoptimize": "^4.0",
"nystudio107/craft-minify": "4.0.0-beta.2",
"nystudio107/craft-retour": "^4.1",
"nystudio107/craft-seomatic": "^4.0",
"servd/craft-asset-storage": "^3.3",
"spicyweb/craft-neo": "^3.7",
"verbb/field-manager": "^3.0",
"vlucas/phpdotenv": "^5.4.0"

CKEditor field on a Assets field layout will not retain its data on save

Steps to reproduce:

  1. Create a Volume and put some assets in it.
  2. Create a CKEditor field and put it on the Volumne's field layout.
  3. Go to Asset index page and double click an asset to edit it.
  4. Add some data in the CKEditor field and save.
  5. Edit the Asset again and notice the data didn't save. No JavaScript errors, looks like it's just missing in POST data on save.

Versions:

  • Craft 3.0.10.1
  • CKEditor 1.0.0-beta2

CK Editor Build (not classic): Change toolbar items based on a users permission level

I believe this functionality was introduced for Redactor. It's the ability to hide/show certain items on the toolbar based on user groups. For Redactor, the configuration lives primarily in Craft or JSON configs. CKEditor requires inline customization (unless I am misunderstanding). In other words, for each editor instance, we need to pass an object in JS to initialize it.

I created a playground (gross code) for me to explore and learn more about it. My long-term goal is to be a builder that will take in environment variables and spit out a CKEditor configuration. I will add additional tickets for some other questions regarding it.

For this ticket, my question in code can be viewed here. I am querying a relative URL (maps to a controller in my module) to return if a user is a superuser. This isn't an ideal solution for tons of reasons, but the obvious reason is that it isn't scalable (required URL be available on all of our sites).

I am wondering if there is a better way? Is the current user's group-level exposed on window.craft? If not, could it be? The end goal for me to be able to change the toolbar based on permissions. I'm not sure what the best way to do it is.

Curiosity question: Is the JS for the admin panel still built with Garnish?

RTL language support

When editing content in Arabic (right-to-left language), the instances of CKEditor are still the left-to-right (and not RTL).
Please note these CKEditor inputs are part of a matrix field. I haven't tested it as a standalone field.

The entry title field is rtl, which means the page reading direction is set correctly.

The div that wraps the CKEditor input wrapping has the following value for the class attribute: "input rtl".

CKEditor require the class "cke_rtl" (as opposed to "rtl") to switch to RTL mode (see https://ckeditor.com/docs/ckeditor4/latest/guide/skin_sdk_rtl.html) That might be the way to fix the issue.

Thanks!

Very poor performance when field is present multiple times.

We have a matrix field with 10 options that our client can use to build their content. Some of those layers make use of the new CKEditor field. While testing, I found that having more than 5 CKEditor fields in your entry takes a big performance hit on the editors browser.

Adding new fields, resizing the browser or editing content within any type of field takes multiple seconds and the fans on my MBP kick in instantly. I have attached a video below where you can see the bad performance when resizing, adding and deleting fields.. This site in the video below is not hosted locally.

CKEditor.poor.performance.mp4

If you need any other information, please let me know.

Live Preview editor mode not working

Hi.

When i add a new text block and typing some random text it does not show up in the preview window. Can't see any errors in the console.

If I then save the entry in Live Preview mode it says that the field is empty and I have to re-enter the text. My text block is required.

Craft CMS RC 8 and CKEditor 1.0.0-beta.2.

[4.x]: When a CKEditor field contains a `<br>` tag it gets marked as changed on focus

What happened?

Description

When a CKEditor field contains a <br> tag it gets marked as changed on focus.

Steps to reproduce

  1. Create a CKEditor field and add it to an entry type.
  2. Go to an entry and type some text in the field, including a <br> tag (eg with SHIFT + ENTER).
  3. Save the entry.
  4. Click in the field, withour typing anything.

Expected behavior

The field should not get marked as changed until the editor actually types something.

Actual behavior

The field gets marked as changed.

Craft CMS version

Craft CMS 4.4.7.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

CKEditor 3.2.0

Top feature requests

Description

I've been taking this for a spin today and the two most important features I see missing are:

  1. The ability to link to Craft entries using the link button in the toolbar.
  2. The ability to define editor configurations once (preferably in a file) and select those configurations when setting up a field, as with the Redactor plugin.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.