From 353e091baa544b5f459cbeb84829a98876a44d8c Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Mon, 28 Oct 2024 11:38:29 +0100 Subject: [PATCH 1/2] BUGFIX: Auto-assign assets to default asset collection for current site This feature existed for default media browser but not for the Media.UI so far --- .../Resolver/Type/MutationResolver.php | 9 +++++--- Classes/Service/AssetCollectionService.php | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Classes/GraphQL/Resolver/Type/MutationResolver.php b/Classes/GraphQL/Resolver/Type/MutationResolver.php index 1076e438e..3892b1489 100644 --- a/Classes/GraphQL/Resolver/Type/MutationResolver.php +++ b/Classes/GraphQL/Resolver/Type/MutationResolver.php @@ -408,9 +408,12 @@ public function uploadFile($_, array $variables): array if ($assetCollectionId) { /** @var AssetCollection $assetCollection */ $assetCollection = $this->assetCollectionRepository->findByIdentifier($assetCollectionId); - if ($assetCollection) { - $asset->setAssetCollections(new ArrayCollection([$assetCollection])); - } + } else { + // Assign the asset to the asset collection of the site it has been uploaded to + $assetCollection = $this->assetCollectionService->getDefaultCollectionForCurrentSite(); + } + if ($assetCollection) { + $asset->setAssetCollections(new ArrayCollection([$assetCollection])); } $this->assetRepository->add($asset); diff --git a/Classes/Service/AssetCollectionService.php b/Classes/Service/AssetCollectionService.php index bb2c09790..90d69022a 100644 --- a/Classes/Service/AssetCollectionService.php +++ b/Classes/Service/AssetCollectionService.php @@ -8,9 +8,12 @@ use Doctrine\ORM\Query\ResultSetMapping; use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface; use Flowpack\Media\Ui\Utility\AssetCollectionUtility; +use Neos\ContentRepository\Domain\Service\ContextFactoryInterface; use Neos\Flow\Annotations as Flow; use Neos\Flow\ObjectManagement\ObjectManagerInterface; +use Neos\Media\Domain\Model\AssetCollection; use Neos\Media\Domain\Repository\AssetCollectionRepository; +use Neos\Neos\Domain\Service\ContentContext; /** * @Flow\Scope("singleton") @@ -37,6 +40,12 @@ class AssetCollectionService */ protected $assetCollectionRepository; + /** + * @Flow\Inject + * @var ContextFactoryInterface + */ + protected $contextFactory; + /** * Queries the asset count for all asset collections once and caches the result. * This helps to avoid a lot of slow queries when rendering the asset collection list. @@ -85,4 +94,17 @@ public function updatePathForNestedAssetCollections(HierarchicalAssetCollectionI $this->updatePathForNestedAssetCollections($childCollection); } } + + /** + * Returns the default asset collection for the current site if available + */ + public function getDefaultCollectionForCurrentSite(): ?AssetCollection + { + /** @var ContentContext $context */ + $context = $this->contextFactory->create([ + 'workspaceName' => 'live', + ]); + + return $context->getCurrentSite()?->getAssetCollection(); + } } From 25595cd7c339825d1643804daeba700c251c0d57 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Mon, 28 Oct 2024 13:01:58 +0100 Subject: [PATCH 2/2] =?UTF-8?q?FEATURE:=20Don=E2=80=99t=20allow=20last=20c?= =?UTF-8?q?ollection=20of=20an=20asset=20in=20=E2=80=9Efolder=20mode?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/GraphQL/Resolver/Type/QueryResolver.php | 10 ++++++++++ Resources/Private/GraphQL/schema.root.graphql | 1 + .../JavaScript/core/src/hooks/useConfigQuery.ts | 2 ++ .../Private/JavaScript/core/src/queries/config.ts | 1 + Resources/Private/JavaScript/dev-server/src/server.ts | 1 + .../SideBarRight/Inspector/CollectionSelectBox.tsx | 7 ++++--- .../Inspector/ParentCollectionSelectBox.tsx | 4 +--- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Classes/GraphQL/Resolver/Type/QueryResolver.php b/Classes/GraphQL/Resolver/Type/QueryResolver.php index 0a09d813d..a59cbc4cd 100644 --- a/Classes/GraphQL/Resolver/Type/QueryResolver.php +++ b/Classes/GraphQL/Resolver/Type/QueryResolver.php @@ -19,6 +19,7 @@ use Flowpack\Media\Ui\GraphQL\Context\AssetSourceContext; use Flowpack\Media\Ui\Infrastructure\Neos\Media\AssetProxyIteratorBuilder; use Flowpack\Media\Ui\Service\AssetChangeLog; +use Flowpack\Media\Ui\Service\AssetCollectionService; use Flowpack\Media\Ui\Service\SimilarityService; use Flowpack\Media\Ui\Service\UsageDetailsService; use Neos\Flow\Annotations as Flow; @@ -114,6 +115,12 @@ class QueryResolver implements ResolverInterface */ protected $privilegeManager; + /** + * @Flow\Inject + * @var AssetCollectionService + */ + protected $assetCollectionService; + /** * Returns total count of asset proxies in the given asset source * @noinspection PhpUnusedParameterInspection @@ -185,10 +192,13 @@ public function assetUsageCount($_, array $variables, AssetSourceContext $assetS */ public function config($_): array { + $defaultAssetCollection = $this->assetCollectionService->getDefaultCollectionForCurrentSite(); + return [ 'uploadMaxFileSize' => $this->getMaximumFileUploadSize(), 'uploadMaxFileUploadLimit' => $this->getMaximumFileUploadLimit(), 'currentServerTime' => (new \DateTime())->format(DATE_W3C), + 'defaultAssetCollectionId' => $defaultAssetCollection ? $this->persistenceManager->getIdentifierByObject($defaultAssetCollection) : null, 'canManageTags' => $this->privilegeManager->isPrivilegeTargetGranted('Flowpack.Media.Ui:ManageTags'), 'canManageAssetCollections' => $this->privilegeManager->isPrivilegeTargetGranted('Flowpack.Media.Ui:ManageAssetCollections'), 'canManageAssets' => $this->privilegeManager->isPrivilegeTargetGranted('Flowpack.Media.Ui:ManageAssets'), diff --git a/Resources/Private/GraphQL/schema.root.graphql b/Resources/Private/GraphQL/schema.root.graphql index e6e8355bd..adae83606 100644 --- a/Resources/Private/GraphQL/schema.root.graphql +++ b/Resources/Private/GraphQL/schema.root.graphql @@ -164,6 +164,7 @@ type Config { uploadMaxFileSize: FileSize! uploadMaxFileUploadLimit: Int! currentServerTime: DateTime! + defaultAssetCollectionId: AssetCollectionId canManageAssetCollections: Boolean! canManageTags: Boolean! canManageAssets: Boolean! diff --git a/Resources/Private/JavaScript/core/src/hooks/useConfigQuery.ts b/Resources/Private/JavaScript/core/src/hooks/useConfigQuery.ts index a6fe2a32e..64f48097a 100644 --- a/Resources/Private/JavaScript/core/src/hooks/useConfigQuery.ts +++ b/Resources/Private/JavaScript/core/src/hooks/useConfigQuery.ts @@ -7,6 +7,7 @@ interface ConfigQueryResult { uploadMaxFileSize: number; uploadMaxFileUploadLimit: number; currentServerTime: Date; + defaultAssetCollectionId: AssetCollectionId | null; canManageAssetCollections: boolean; canManageTags: boolean; canManageAssets: boolean; @@ -18,6 +19,7 @@ const DEFAULT_CONFIG: ConfigQueryResult = { uploadMaxFileSize: 0, uploadMaxFileUploadLimit: 0, currentServerTime: new Date(), + defaultAssetCollectionId: null, canManageAssetCollections: false, canManageTags: false, canManageAssets: false, diff --git a/Resources/Private/JavaScript/core/src/queries/config.ts b/Resources/Private/JavaScript/core/src/queries/config.ts index d6dbb5f88..5c6e82f66 100644 --- a/Resources/Private/JavaScript/core/src/queries/config.ts +++ b/Resources/Private/JavaScript/core/src/queries/config.ts @@ -6,6 +6,7 @@ const CONFIG = gql` uploadMaxFileSize uploadMaxFileUploadLimit currentServerTime + defaultAssetCollectionId canManageAssetCollections canManageTags canManageAssets diff --git a/Resources/Private/JavaScript/dev-server/src/server.ts b/Resources/Private/JavaScript/dev-server/src/server.ts index 4e6235e47..4a01884b2 100644 --- a/Resources/Private/JavaScript/dev-server/src/server.ts +++ b/Resources/Private/JavaScript/dev-server/src/server.ts @@ -164,6 +164,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); uploadMaxFileSize: 1024 * 1024, uploadMaxFileUploadLimit: 2, currentServerTime: new Date(), + defaultAssetCollectionId: null, canManageAssetCollections: true, canManageTags: true, canManageAssets: true, diff --git a/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/CollectionSelectBox.tsx b/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/CollectionSelectBox.tsx index 221125bce..393cd6674 100644 --- a/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/CollectionSelectBox.tsx +++ b/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/CollectionSelectBox.tsx @@ -4,7 +4,7 @@ import { useRecoilValue } from 'recoil'; import { Headline, MultiSelectBox, SelectBox } from '@neos-project/react-ui-components'; import { useIntl, useNotify, useMediaUi } from '@media-ui/core'; -import { useSelectedAsset, useSetAssetCollections } from '@media-ui/core/src/hooks'; +import { useConfigQuery, useSelectedAsset, useSetAssetCollections } from '@media-ui/core/src/hooks'; import { IconLabel } from '@media-ui/core/src/components'; import { featureFlagsState } from '@media-ui/core/src/state'; import { collectionPath, useAssetCollectionsQuery } from '@media-ui/feature-asset-collections'; @@ -19,6 +19,7 @@ const collectionsMatchAsset = (assetCollectionIds: string[], asset: Asset) => { const CollectionSelectBox: React.FC = () => { const Notify = useNotify(); const { translate } = useIntl(); + const { config } = useConfigQuery(); const { approvalAttainmentStrategy: { obtainApprovalToSetAssetCollections }, } = useMediaUi(); @@ -136,7 +137,7 @@ const CollectionSelectBox: React.FC = () => { onSearchTermChange={handleSearchTermChange} ListPreviewElement={AssetCollectionOptionPreviewElement} displaySearchBox - allowEmpty + allowEmpty={false} threshold={0} /> @@ -158,7 +159,7 @@ const CollectionSelectBox: React.FC = () => { onSearchTermChange={handleSearchTermChange} ListPreviewElement={AssetCollectionOptionPreviewElement} displaySearchBox - allowEmpty + allowEmpty={!config.defaultAssetCollectionId} threshold={0} /> diff --git a/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/ParentCollectionSelectBox.tsx b/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/ParentCollectionSelectBox.tsx index 5c2859a59..ff7ee2eee 100644 --- a/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/ParentCollectionSelectBox.tsx +++ b/Resources/Private/JavaScript/media-module/src/components/SideBarRight/Inspector/ParentCollectionSelectBox.tsx @@ -4,7 +4,6 @@ import { Headline, SelectBox } from '@neos-project/react-ui-components'; import { useIntl, useMediaUi, useNotify } from '@media-ui/core'; import { IconLabel } from '@media-ui/core/src/components'; -import { useConfigQuery } from '@media-ui/core/src/hooks'; import { collectionPath, useAssetCollectionsQuery, @@ -18,7 +17,6 @@ import * as classes from './ParentCollectionSelectBox.module.css'; const ParentCollectionSelectBox = () => { const Notify = useNotify(); - const { config } = useConfigQuery(); const { translate } = useIntl(); const { approvalAttainmentStrategy } = useMediaUi(); const { assetCollections } = useAssetCollectionsQuery(); @@ -98,7 +96,7 @@ const ParentCollectionSelectBox = () => {