/**
  * In this method you can add children for a specific parent, but also remove and change the already created children
  *
  * @param MenuBuilder $menu The MenuBuilder
  * @param MenuItem[] &$children The current children
  * @param MenuItem $parent The parent Menu item
  * @param Request $request The Request
  */
 public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
 {
     if (is_null($parent)) {
         // Add menu item for root gallery
         $rootFolders = $this->repo->getRootNodes();
         $currentId = $request->get('folderId');
         $currentFolder = null;
         if (isset($currentId)) {
             /* @var Folder $currentFolder */
             $currentFolder = $this->repo->find($currentId);
         }
         /** @var Folder $rootFolder */
         foreach ($rootFolders as $rootFolder) {
             $menuItem = new TopMenuItem($menu);
             $menuItem->setRoute('KunstmaanMediaBundle_folder_show')->setRouteparams(array('folderId' => $rootFolder->getId()))->setUniqueId('folder-' . $rootFolder->getId())->setLabel($rootFolder->getName())->setParent(null)->setRole($rootFolder->getRel());
             if (!is_null($currentFolder)) {
                 $parentIds = $this->repo->getParentIds($currentFolder);
                 if (in_array($rootFolder->getId(), $parentIds)) {
                     $menuItem->setActive(true);
                 }
             }
             $children[] = $menuItem;
         }
     }
 }
 /**
  * @param $filePath string  The full filepath of the asset you want to upload. The filetype will be automatically detected.
  * @param $folderId integer For now you still have to manually pass the correct folder ID.
  *
  * @return Media
  */
 public function createFile($filePath, $folderId)
 {
     $fileHandler = $this->container->get('kunstmaan_media.media_handlers.file');
     // Get file from FilePath.
     $data = new File($filePath, true);
     /** @var $media Media */
     $media = $fileHandler->createNew($data);
     /** @var $folder Folder */
     $folder = $this->folderRepository->getFolder($folderId);
     $media->setFolder($folder);
     $fileHandler->prepareMedia($media);
     $fileHandler->updateMedia($media);
     $fileHandler->saveMedia($media);
     $this->em->persist($media);
     $this->em->flush();
     return $media;
 }
 /**
  * @param Folder $folder
  *
  * @return array
  */
 public function getParents(Folder $folder)
 {
     return $this->repository->getPath($folder);
 }