CKFinder 插件 - PHP - 如果在重命名文件夹时找到,则删除 Space

CKFinder Plugin - PHP - Remove Space if Found when Renaming a Folder

我需要社区的帮助,我需要创建一个插件来检查用户在重命名文件夹时的输入。该插件应检查新的 Renamed 文件夹,并在保存之前删除找到的任何 space。

我卡在 removeFolderSpace 函数中,不知道如何完成它。如果有人愿意帮助,我将不胜感激!

<?php
namespace CKSource\CKFinder\Plugin\FolderSpace;

use CKSource\CKFinder\Acl\Permission;
use CKSource\CKFinder\CKFinder;
use CKSource\CKFinder\Config;
use CKSource\CKFinder\Command\CommandAbstract;
use CKSource\CKFinder\Event\CKFinderEvent;
use CKSource\CKFinder\Event\RenameFolderEvent;
use CKSource\CKFinder\Filesystem\Folder\Folder;
use CKSource\CKFinder\Filesystem\Folder\WorkingFolder;
use CKSource\CKFinder\Plugin\PluginInterface;
use CKSource\CKFinder\Filesystem\Path;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class FolderSpace implements PluginInterface, EventSubscriberInterface
{
    protected $app;

    public function setContainer(CKFinder $app) {
        $this->app = $app;
    }

    protected $requires = [
        Permission::FOLDER_RENAME,
    ];

    public function getDefaultConfig() {
        return [];
    }

    public function removeFolderSpace(RenameFolderEvent $event) {
        $config = $this->app['config'];
        //$dispatcher = $this->app['dispatcher'];

        // $dispatcher->addListener(CKFinderEvent::AFTER_COMMAND_RENAME_FILE, function(AfterCommandEvent $e) {

        // });

        $request = $event->getRequest();


        $workingFolder = $this->app['working_folder'];



    }


    public static function getSubscribedEvents()
    {
        return [CKFinderEvent::AFTER_COMMAND_RENAME_FILE => 'removeFolderSpace'];
    }


}

要实现此结果,您需要为前端 (JavaScript) 和连接器 (PHP) 创建一个小插件。

PHP插件bootstrap代码:

namespace CKSource\CKFinder\Plugin\SanitizeFolderName;

use CKSource\CKFinder\CKFinder;
use CKSource\CKFinder\Event\CKFinderEvent;
use CKSource\CKFinder\Event\RenameFolderEvent;
use CKSource\CKFinder\Plugin\PluginInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class SanitizeFolderName implements PluginInterface, EventSubscriberInterface
{
    protected $app;

    public function setContainer(CKFinder $app)
    {
        $this->app = $app;
    }

    public function getDefaultConfig()
    {
        return [];
    }

    public function onFolderRename(RenameFolderEvent $event)
    {
        $event->setNewFolderName(str_replace(' ', '_', $event->getNewFolderName()));
    }

    public static function getSubscribedEvents()
    {
        return [
            CKFinderEvent::RENAME_FOLDER => 'onFolderRename'
        ];
    }
}

JavaScript代码:

CKFinder.start({
    onInit: function(finder) {
        finder.on('command:before:RenameFolder', function() {
            finder.once('command:before:GetFiles', function(evt) {
                var folder = evt.data.folder;
                folder.set('name', folder.get('name').replace(/ /g, '_'));
            });
        });
    }
});