Skip to content

Commit

Permalink
Merge pull request #9 from Flowpack/8-feature-exclude-node-types-from…
Browse files Browse the repository at this point in the history
…-usage-count

FEATURE: Exclude node types from usage count
  • Loading branch information
Sebobo authored Feb 15, 2023
2 parents f0ddc68 + d437a6d commit 3843b6f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Classes/Service/AssetIntegrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ final class AssetIntegrationService
*/
protected $assetUsageLogger;

/**
* @Flow\InjectConfiguration(path="excludedNodeTypes")
* @var array
*/
protected $excludedNodeTypes;

private $assetPropertiesByNodeType = [];

public function assetRemoved(AssetInterface $asset): void
Expand Down Expand Up @@ -104,6 +110,13 @@ public function getAssetPropertyNamesForNodeType(NodeType $nodeType): array
return $this->assetPropertiesByNodeType[$nodeType->getName()];
}

foreach ($this->excludedNodeTypes as $excludedNodeType) {
if ($nodeType->isOfType($excludedNodeType)) {
$this->assetPropertiesByNodeType[$nodeType->getName()] = [];
return [];
}
}

$propertyNames = array_reduce(array_keys($nodeType->getProperties()),
function ($carry, $propertyName) use ($nodeType) {
if ($this->propertyTypeCanBeRegistered($nodeType->getPropertyType($propertyName))) {
Expand Down
4 changes: 4 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Flowpack:
Neos:
AssetUsage:
excludedNodeTypes: []
23 changes: 23 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ When that happens, it is important that you try to find out where they come from
If you think this happened due to an error in this package, please open an issue
with as much information as you can give.

## Feature: Exclude node types from usage count

Possible use case: If you are using this package in combination with [neos/metadata-contentrepositoryadapter](https://github.com/neos/metadata-contentrepositoryadapter), the metadata entries will be recognized as usage count. You can adjust this behaviour with the following settings.

Example to exclude all metadata node types from usage count:
```
Flowpack:
Neos:
AssetUsage:
excludedNodeTypes:
- 'Neos.MetaData:AbstractMetaData'
```

Example to exclude multiple custom metadata node types:
```
Flowpack:
Neos:
AssetUsage:
excludedNodeTypes:
- 'Vendor.PackageName:Custom.MetaData.NodeType1'
- 'Vendor.PackageName:Custom.MetaData.NodeType2'
```

## Related packages

* [Flowpack.EntityUsage](https://github.com/Flowpack/Flowpack.EntityUsage) the generic usage implementation
Expand Down

0 comments on commit 3843b6f

Please sign in to comment.