Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory Tree Renderer #86

Open
mogilvie opened this issue Jun 9, 2021 · 5 comments
Open

Directory Tree Renderer #86

mogilvie opened this issue Jun 9, 2021 · 5 comments

Comments

@mogilvie
Copy link

mogilvie commented Jun 9, 2021

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
Copy link
Owner

artgris commented Jun 10, 2021

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
Copy link
Author

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
Copy link
Owner

artgris commented Jun 10, 2021

An event dispatcher is a good idea and very flexible 🤔 👍

@Martin1982
Copy link
Contributor

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants