/
ExternalFileProviderOptionTrait.php
49 lines (42 loc) · 1.97 KB
/
ExternalFileProviderOptionTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Concrete\Core\File\Component\Chooser;
use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Entity\User\User;
use Concrete\Core\File\Filesystem;
use Concrete\Core\Support\Facade\Application;
use Doctrine\ORM\EntityManagerInterface;
trait ExternalFileProviderOptionTrait
{
public function jsonSerialize()
{
$user = new \Concrete\Core\User\User();
$app = Application::getFacadeApplication();
/** @var EntityManagerInterface $entityManager */
$entityManager = $app->make(EntityManagerInterface::class);
/** @var Repository $config */
$config = $app->make(Repository::class);
$userRepository = $entityManager->getRepository(User::class);
/** @var User $userEntity */
$userEntity = $userRepository->findOneBy(["uID" => $user->getUserID()]);
$fileSystem = new Filesystem();
$uploadDirectoryId = (string)$fileSystem->getRootFolder()->getTreeNodeID();
if ($config->has("concrete.external_file_providers.preferred_upload_directory_id")) {
$uploadDirectoryId = $config->get("concrete.external_file_providers.preferred_upload_directory_id");
}
if ($userEntity->getHomeFileManagerFolderID() !== null) {
$uploadDirectoryId = (string)$userEntity->getHomeFileManagerFolderID();
}
return [
'id' => $this->getId(),
'componentKey' => $this->getComponentKey(),
'title' => $this->getTitle(),
'data' => [
'typeHandle' => $this->externalFileProvider->getTypeObject()->getHandle(),
'name' => $this->externalFileProvider->getName(),
'supportFileTypes' => $this->externalFileProvider->getConfigurationObject()->supportFileTypes(),
'hasCustomImportHandler' => $this->externalFileProvider->getConfigurationObject()->hasCustomImportHandler(),
'uploadDirectoryId' => $uploadDirectoryId
],
];
}
}