CKEditor mentions compatible with CKEditor 5?

Created on 14 September 2022, about 2 years ago
Updated 22 June 2023, over 1 year ago

Problem/Motivation

Steps to reproduce

Proposed resolution

Use CKEditor 5's https://ckeditor.com/docs/ckeditor5/latest/features/mentions.html plugin.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

🇦🇹Austria maxilein

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • @falco010 opened merge request.
  • 🇳🇱Netherlands falco010 🇳🇱 The Netherlands

    Hi all, moved the work done by @webflo to an issue fork:
    https://git.drupalcode.org/project/ckeditor_mentions/-/merge_requests/11...

    I added the javascript from tarball to the fork (and changed the library path):

    npm view @ckeditor/ckeditor5-mention
    => unpack dist.tarball url
    

    Added it in js/ckeditor5_plugins/mention.js

    However the mention.js gave an error on line 254:
    if (!n.canEditAt(a)) return;
    So commented that out for now (which does not seem to break anything).

    We also had errors with deprecated EventDispatcher, therefor we changed:
    use Symfony\Component\EventDispatcher\Event;
    to
    use Drupal\Component\EventDispatcher\Event;

    After these minor tweaks we managed to get this working locally:

    We used to have avatars in the mentions, but that stopped working unfortunatly, not sure why yet.

    Drupal core version used: 10.0.9

    This might also be the right time to bump this work to a major 3.x version and clean up:

    • src/CKEditorMentionEvent.php
    • src/CKEditorMentionSuggestionEvent.php
  • 🇳🇱Netherlands falco010 🇳🇱 The Netherlands
  • 🇳🇱Netherlands falco010 🇳🇱 The Netherlands

    To use this issue fork in your project, add this to your composer repositories:

            {
                "type": "git",
                "url": "https://git.drupalcode.org/issue/ckeditor_mentions-3309677.git"
            },
    

    And run the following command:

    composer require drupal/ckeditor_mentions:dev-3309677-ckeditor-mentions-compatible
    
  • Assigned to dinazaur
  • 🇺🇦Ukraine dinazaur

    A bit messy here. Webflo still commits in his fork on GitHub ignoring MR here. Nice :)

  • 🇩🇪Germany webflo

    @dinazaur Hi, I am a new maintainer since a few days. I will push my code from Github and then view and merge the other changes. Please be patient. Thanks!

  • 🇺🇦Ukraine dinazaur

    I hope by merging you mean assigning a ticket for someone to review. We need to separate Mention entities and ckeditor5 into two separate tickets. For entity creation, we could make integration with mentions module if we want to because the module already provides entities, and I don't see any reason to make entities here and to complicate this module.

  • 🇩🇪Germany webflo

    Sure, lets work on it together. Mentions module can only track references to user entities, but ckeditor_mentions can reference other entities. ckeditor_mentions_entity uses dynamic_entity_reference for this use-case. Of course it possible to remove the submodule. I will maintain in a other repo.

  • 🇺🇦Ukraine dinazaur

    I just looked at a few ckeditor modules in order to find out what is the best solution for adding the @ckeditor/ckeditor5-mention plugin into the module. Since all CKeditor5 plugins are easily installable via composer (https://asset-packagist.org/package/npm-asset/ckeditor--ckeditor5-mention) we could add instructions on how to install it from composer. But maybe it would be better to install a specific version using npm and import it into the final plugin build since we are using Webpack already. In that way, we will ensure that it will for sure work because the user can install a newer version with some breaking changes.

  • 🇩🇪Germany webflo

    The latest code is in https://git.drupalcode.org/issue/ckeditor_mentions-3309677/-/tree/330967...

    I refactored the JS Plugin names a little bit. It includes ckeditor_mentions_entity and the the changes from @Falco010. I made the number of items in the autocomplete configurable.

    @dinazaur Please review the code. Maybe everything except ckeditor_mentions_entity. Thanks!

  • Merge request !12CK5 → (Merged) created by webflo
  • 🇺🇦Ukraine dinazaur

    Hi, I will have a look at this MR over the weekend.

  • 🇺🇦Ukraine dinazaur

    Okay, I just made a few changes. What's left to do is to implement an upgrade path, and remove unneeded properties from configuration. Apart from that it's ready for review.

  • Issue was unassigned.
  • Status changed to Needs work 11 months ago
  • Status changed to Fixed 10 months ago
  • 🇺🇦Ukraine dinazaur

    Hello there. It was a long way. Let's merge it into 3.x branch and create a beta release. I'll create a follow-up ticket for tests adjustment.

  • 🇺🇦Ukraine dinazaur

    @lazzyvn

    Check on ckeditor5, it work great
    Can you support some module notification please

    This is a straightforward implementation in custom code. You just need to react to the Mentions event. I don't see any reason why we need to implement such thing in this module.

  • 🇫🇷France lazzyvn paris

    Can you write down exemple for custom module please.

  • 🇺🇦Ukraine dinazaur
    <?php
    
    namespace Drupal\example\EventSubscriber;
    
    use Drupal\ckeditor_mentions\Events\CKEditorEvents;
    use Drupal\ckeditor_mentions\Events\CKEditorMentionsEvent;
    use Drupal\message\Entity\Message;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class Example implements EventSubscriberInterface {
    
      public static function getSubscribedEvents() {
        return [CKEditorEvents::MENTION_FIRST => ['onMention']];
      }
    
      public function onMention(CKEditorMentionsEvent $event) {
        if ($event->getPlugin()->getPluginId() !== 'user') {
          return;
        }
    
        $notification = Message::create([
          'template' => 'some_template_id',
          'uid' => $event->getMentionedEntity()->id(),
        ]);
        $notification->save();
    
        \Drupal::service('message_notify.sender')->send($notification);
      }
    
    }
    
    
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇮🇳India sushyl@gmail.com Pune

    sushyl changed the visibility of the branch 3309677-ckeditor-mentions-compatible to hidden.

Production build 0.71.5 2024