2017-12-11 15 views
0

커뮤니티 도움말이 필요하므로 폴더 이름을 변경할 때 사용자 입력을 확인하는 플러그인을 만들어야합니다. 플러그인은 새 이름이 바뀐 폴더를 확인해야하며 저장하기 전에 찾은 공간을 제거해야합니다.CKFinder 플러그인 - PHP - 폴더 이름을 바꿀 때 공백을 제거하면

나는 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']; 
    } 


} 

답변

0

이 결과를 얻으려면 frontend (JavaScript)와 connector (PHP)의 작은 플러그인을 만들어야합니다.

PHP 플러그인 부트 스트랩 코드 :

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' 
     ]; 
    } 
} 

코드 자바 스크립트 :

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, '_')); 
      }); 
     }); 
    } 
}); 
+0

귀하의 코드는 CreateFolder를 명령에 근무하지만 폴더는 오류 및 화면 공백을 표시 이름을 바꿀 때마다 나는 RenameFolder 때와 프런트 엔드에서 ckfinder를 열었을 때마다 오류가 발생하지만 파일 구조에서 폴더 이름이 변경됩니다. 로그에 WorkingFolder가없는 것으로 표시됩니다. –