-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from Flowpack/feature/hierarchical-asset-coll…
…ections FEATURE: Hierarchical asset collections
- Loading branch information
Showing
413 changed files
with
14,493 additions
and
16,196 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.yarn/patches/@neos-project-neos-ui-extensibility-webpack-adapter-npm-8.3.0-fcedc456c3.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
diff --git a/scripts/helpers/webpack.config.js b/scripts/helpers/webpack.config.js | ||
index 25930d442a5aec4d22f1e890bd061ea3256570af..9f94a69f2892c156c5b2da64ba56363ffdaa1dfc 100644 | ||
--- a/scripts/helpers/webpack.config.js | ||
+++ b/scripts/helpers/webpack.config.js | ||
@@ -135,6 +135,11 @@ module.exports = function (neosPackageJson) { | ||
} | ||
], | ||
}, | ||
+ performance: { | ||
+ hints : false, | ||
+ maxEntrypointSize: 1000000, | ||
+ maxAssetSize: 1000000 | ||
+ }, | ||
entry: { | ||
Plugin: './src/index.js' | ||
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flowpack\Media\Ui\Aspect; | ||
|
||
/* | ||
* This file is part of the Flowpack.Media.Ui package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Aop\JoinPointInterface; | ||
use Neos\Media\Domain\Model\AssetCollection; | ||
use Neos\Utility\ObjectAccess; | ||
|
||
/** | ||
* An aspect for adding hierarchical relations to the Neos.Media AssetCollection entity | ||
* This is a AOP patch until the same functionality is merged into the Neos core | ||
* | ||
* @Flow\Introduce("class(Neos\Media\Domain\Model\AssetCollection)", interfaceName="Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface") | ||
* @Flow\Aspect | ||
*/ | ||
class HierarchicalAssetCollectionAspect | ||
{ | ||
|
||
/** | ||
* @var AssetCollection | ||
* @ORM\ManyToOne(cascade={"persist"}) | ||
* @ORM\JoinColumn(onDelete="SET NULL") | ||
* @Flow\Lazy | ||
* @Flow\Introduce("class(Neos\Media\Domain\Model\AssetCollection)") | ||
*/ | ||
protected $parent; | ||
|
||
/** | ||
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->getParent())") | ||
*/ | ||
public function getParent(JoinPointInterface $joinPoint): ?HierarchicalAssetCollectionInterface | ||
{ | ||
/** @var HierarchicalAssetCollectionInterface $assetCollection */ | ||
$assetCollection = $joinPoint->getProxy(); | ||
return ObjectAccess::getProperty($assetCollection, 'parent', true); | ||
} | ||
|
||
/** | ||
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->setParent())") | ||
*/ | ||
public function setParent(JoinPointInterface $joinPoint): void | ||
{ | ||
/** @var HierarchicalAssetCollectionInterface $assetCollection */ | ||
$assetCollection = $joinPoint->getProxy(); | ||
/** @var HierarchicalAssetCollectionInterface $parentAssetCollection */ | ||
$parentAssetCollection = $joinPoint->getMethodArgument('parent'); | ||
if (!$parentAssetCollection instanceof AssetCollection && $parentAssetCollection !== null) { | ||
throw new \InvalidArgumentException('Parent must be an AssetCollection', 1678330583); | ||
} | ||
ObjectAccess::setProperty($assetCollection, 'parent', $parentAssetCollection, true); | ||
|
||
// Throws an error if a circular dependency has been detected | ||
$parent = $assetCollection->getParent(); | ||
while ($parent !== null) { | ||
$parent = $parent->getParent(); | ||
if ($parent === $assetCollection->getParent()) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Circular reference detected, parent AssetCollection "%s" appeared twice in the hierarchy', | ||
$parent->getTitle() | ||
), 1678330856); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->unsetParent())") | ||
*/ | ||
public function unsetParent(JoinPointInterface $joinPoint): void | ||
{ | ||
/** @var HierarchicalAssetCollectionInterface $assetCollection */ | ||
$assetCollection = $joinPoint->getProxy(); | ||
ObjectAccess::setProperty($assetCollection, 'parent', null, true); | ||
} | ||
|
||
/** | ||
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->hasParent())") | ||
*/ | ||
public function hasParent(JoinPointInterface $joinPoint): bool | ||
{ | ||
/** @var HierarchicalAssetCollectionInterface $assetCollection */ | ||
$assetCollection = $joinPoint->getProxy(); | ||
return ObjectAccess::getProperty($assetCollection, 'parent', true) !== null; | ||
} | ||
|
||
/** | ||
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->getTitle())") | ||
*/ | ||
public function getTitle(JoinPointInterface $joinPoint): string | ||
{ | ||
/** @var AssetCollection $assetCollection */ | ||
$assetCollection = $joinPoint->getProxy(); | ||
return $assetCollection->getTitle(); | ||
} | ||
|
||
/** | ||
* @Flow\Around("method(Neos\Media\Domain\Model\AssetCollection->getTags())") | ||
*/ | ||
public function getTags(JoinPointInterface $joinPoint): Collection | ||
{ | ||
/** @var AssetCollection $assetCollection */ | ||
$assetCollection = $joinPoint->getProxy(); | ||
return $assetCollection->getTags(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Classes/Aspect/HierarchicalAssetCollectionRepositoryAspect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flowpack\Media\Ui\Aspect; | ||
|
||
/* | ||
* This file is part of the Flowpack.Media.Ui package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Flowpack\Media\Ui\Domain\Model\HierarchicalAssetCollectionInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Aop\JoinPointInterface; | ||
use Neos\Flow\Persistence\QueryResultInterface; | ||
use Neos\Media\Domain\Model\AssetCollection; | ||
use Neos\Media\Domain\Repository\AssetCollectionRepository; | ||
use Neos\Utility\ObjectAccess; | ||
|
||
/** | ||
* An aspect for adding hierarchical relations to the Neos.Media AssetCollection entity | ||
* This is a AOP patch until the same functionality is merged into the Neos core | ||
* | ||
* @Flow\Aspect | ||
*/ | ||
class HierarchicalAssetCollectionRepositoryAspect | ||
{ | ||
/** | ||
* Remove all child collections recursively to prevent orphaned collections | ||
* | ||
* @Flow\Around("method(Neos\Media\Domain\Repository\AssetCollectionRepository->remove())") | ||
*/ | ||
public function remove(JoinPointInterface $joinPoint): void | ||
{ | ||
/** @var AssetCollectionRepository $assetCollectionRepository */ | ||
$assetCollectionRepository = $joinPoint->getProxy(); | ||
/** @var AssetCollection $assetCollection */ | ||
$assetCollection = $joinPoint->getMethodArgument('object'); | ||
$persistenceManager = ObjectAccess::getProperty($assetCollectionRepository, 'persistenceManager', true); | ||
|
||
$deleteRecursively = static function (AssetCollection $collection) use (&$deleteRecursively, $persistenceManager, $assetCollectionRepository) { | ||
$childCollections = $assetCollectionRepository->findByParent($collection); | ||
foreach ($childCollections as $childCollection) { | ||
$deleteRecursively($childCollection); | ||
} | ||
$persistenceManager->remove($collection); | ||
}; | ||
$deleteRecursively($assetCollection); | ||
} | ||
} |
Oops, something went wrong.