artgris / FileManagerBundle

FileManager is a simple Multilingual File Manager Bundle for Symfony
MIT License
171 stars 89 forks source link

Directory Tree Renderer #86

Open mogilvie opened 3 years ago

mogilvie commented 3 years ago

Hi, I'd like to use the bundle for a multi-user application. I'd like to keep the actual director folder name as something immutable, such as a user UUID number, but display the directory folder as the user name .

There are several means of accomplishing this, and I would be happy to do a pull request with changes. I'm wondering if you have a preferred method?

Regards, Mark

artgris commented 3 years ago

Hi @mogilvie , Do you have a method in mind? I just want to keep my bundle simple and not be dependent on a database.

mogilvie commented 3 years ago

Add an additional array item for the directory list called 'fileSystemText, as opposed to 'text', which would be used for display in the directory tree tree. If fileSystemText was empty or unset then 'text' would be used.

Add an event dispatcher that allows the main application manage its own DB or logic to set the fileSystemName based on the Finder object.

artgris commented 3 years ago

An event dispatcher is a good idea and very flexible :thinking: :+1:

Martin1982 commented 2 years ago

The way we solved this is indeed with a listener;

<?php
/**
 * Class FileManagerSubscriber
 */
class FileManagerSubscriber implements EventSubscriberInterface
{
    /**
     * @param GenericEvent $event
     *
     * @return void
     */
    public function onDirectoriesScanned(GenericEvent $event): void
    {
        /** @var Finder $finder */
        $finder = $event->getArgument('finder');

        // @todo Create this method to return the paths you want to present to your user as an array
        $allowedPaths = $this->getAllowedPathsArray();

        $finder->filter(function (\SplFileInfo $file) use ($allowedPaths) {
            if (in_array($file->getRealPath(), $allowedPaths, false)) {
                return true;
            }

            return false;
        });
    }

    /**
     * @inheritDoc
     */
    public static function getSubscribedEvents(): array
    {
        return [
            FileManagerEvents::POST_DIRECTORY_FILTER_CONFIGURATION => 'onDirectoriesScanned',
        ];
    }
}
mogilvie commented 2 years ago

Thankyou @Martin1982 , that's a great suggestion to use the FileManagerEvent.