Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add select for nodetype field #5

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/Controller/NodeTypeFinderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function initializeView(ViewInterface $view)
public function indexAction(?string $searchTerm = null): void
{
$this->view->assign('searchTerm', $searchTerm);
$this->view->assign('nodeTypes', $this->nodeTypeFinderService->getRelevantNodeTypes());

if (!empty($searchTerm)) {
$this->view->assign('occurrences', iterator_to_array($this->search($searchTerm)));
Expand Down
16 changes: 16 additions & 0 deletions Classes/Service/NodeTypeFinderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace Netlogix\NodeTypeFinder\Service;

use Neos\ContentRepository\Domain\Model\NodeType;
use Neos\ContentRepository\Domain\Service\ContentDimensionCombinator;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Eel\FlowQuery\FlowQuery;
Expand Down Expand Up @@ -41,6 +43,12 @@ class NodeTypeFinderService
*/
protected $userService;

/**
* @var NodeTypeManager
* @Flow\Inject
*/
protected $nodeTypeManager;

/**
* @param string $nodeTypeName
* @param ControllerContext $controllerContext
Expand Down Expand Up @@ -77,6 +85,14 @@ public function findNodeTypeOccurrences(string $nodeTypeName, ControllerContext
return array_values($occurrences);
}

public function getRelevantNodeTypes(): array
{
$nodeTypes = $this->nodeTypeManager->getNodeTypes(false);
$nodeTypes = array_filter($nodeTypes, fn (NodeType $nodeType) => $nodeType->isOfType('Neos.Neos:Document') || $nodeType->isOfType('Neos.Neos:Content'));

return array_map(fn (NodeType $nodeType) => ['name' => $nodeType->getName(), 'label' => $nodeType->getLabel()], $nodeTypes);
}

private function findNodeTypeOccurrencesInAllDimensions(string $nodeTypeName): iterable
{
$dimensionCombinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
Expand Down
44 changes: 25 additions & 19 deletions Resources/Private/Fusion/Backend/NodeTypeFinder.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ prototype(Netlogix.NodeTypeFinder:BackendModule) < prototype(Neos.Fusion:Compone
<Neos.Fusion.Form:Form form.data.searchTerm={searchTerm} form.target.action="index">
<div class="neos-row">
<Neos.Fusion.Form:Neos.BackendModule.FieldContainer attributes.class="neos-span4" field.name="searchTerm" >
<Neos.Fusion.Form:Input attributes.class="neos-span4" attributes.placeholder="Vendor.Package.NodeTypes:NodeType" />
<Neos.Fusion.Form:Select attributes.class="neos-span4">
<Neos.Fusion:Loop items={nodeTypes} itemName="nodeType" @children="itemRenderer">
<Neos.Fusion.Form:Select.Option option.value={nodeType.name}>
{nodeType.label ? nodeType.label + ' (' + nodeType.name + ')' : nodeType.name}
</Neos.Fusion.Form:Select.Option>
</Neos.Fusion:Loop>
</Neos.Fusion.Form:Select>
</Neos.Fusion.Form:Neos.BackendModule.FieldContainer>
<Neos.Fusion.Form:Button attributes.class="neos-button neos-button-primary">
Search
Expand Down Expand Up @@ -37,24 +43,24 @@ prototype(Netlogix.NodeTypeFinder:BackendModule) < prototype(Neos.Fusion:Compone
}

prototype(Netlogix.NodeTypeFinder:BackendModule.Occurrence) < prototype(Neos.Fusion:Component) {
occurrence = ${occurrence}
hiddenProps = Neos.Fusion:DataStructure {
style = Neos.Fusion:Join {
0 = 'color: #777'
@glue = ';'
}
occurrence = ${occurrence}
hiddenProps = Neos.Fusion:DataStructure {
style = Neos.Fusion:Join {
0 = 'color: #777'
@glue = ';'
}

@if.hidden = ${occurrence.visible == false}
}
@if.hidden = ${occurrence.visible == false}
}

renderer = afx`
<tr>
<td>
<a href={props.occurrence.url} {...props.hiddenProps}>
{props.occurrence.label}
</a>
</td>
<td {...props.hiddenProps}>{props.occurrence.url}</td>
</tr>
`
renderer = afx`
<tr>
<td>
<a href={props.occurrence.url} {...props.hiddenProps}>
{props.occurrence.label}
</a>
</td>
<td {...props.hiddenProps}>{props.occurrence.url}</td>
</tr>
`
}