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: Placeholder-Insert: Exclude specific NodeTypes from the drop… #100

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions Configuration/NodeTypes.Finishers.Confirmation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
# Alternatively enable a rich text editor:
# editor: 'Neos.Neos/Inspector/Editors/RichTextEditor'
# editorOptions:
# nodeTypes:
# 'Neos.Form.Builder:ElementCollection':
# includeNodeType: false # excludes only the NodeType
# includeChildNodes: true # includes all child-nodes
# 'Neos.Form.Builder:ValidatorCollection': false # excludes the NodeType and all child-nodes
# formatting:
# placeholderInsert: true
# strong: true
Expand Down
5 changes: 5 additions & 0 deletions Configuration/NodeTypes.Finishers.Email.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
# Alternatively enable a rich text editor:
# editor: 'Neos.Neos/Inspector/Editors/RichTextEditor'
# editorOptions:
# nodeTypes:
# 'Neos.Form.Builder:ElementCollection':
# includeNodeType: false # excludes only the NodeType
# includeChildNodes: true # includes all child-nodes
# 'Neos.Form.Builder:ValidatorCollection': false # excludes the NodeType and all child-nodes
# formatting:
# placeholderInsert: true
# strong: true
Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,51 @@ selectable:
}
}
```

## Example: Exclude NodeTypes from the Placeholder-Insert

If you do not want that some NodeTypes are visible in the `Placeholder-Insert`-Dropdown then you can hide them easily.

__This option requires the RichText-Editor.__

Edit the YAML-Configuration of the Confirmation or Email-Finisher:

```yaml
'Neos.Form.Builder:EmailFinisher':
properties:
'templateSource':
ui:
inspector:
editor: 'Neos.Neos/Inspector/Editors/RichTextEditor'
editorOptions:
nodeTypes:
'Foo.Bar:GridCollection':
includeNodeType: false # excludes only the NodeType
includeChildNodes: true # includes all child-nodes
'Neos.Form.Builder:ValidatorCollection': true # includes the NodeType and all child-nodes
'Neos.Form.Builder:SelectionOptionCollection': false # excludes the NodeType and all child-nodes
```

At the path `templateSource.ui.inspector.editorOption.nodeTypes` you can hide or show specific NodeTypes.

If you use the NodeType-Name as the key and a boolean-value as the value, these settings are having an effect on the whole NodeType and the child-nodes of the created node of that NodeType.<br>
```yaml
nodeTypes:
'Foo.Bar:GridCollection': true # shows the NodeType and all child-nodes
'Foo.Bar:SelectionOptionCollection': false # hides the NodeType and all child-nodes
```

If you want only hide the NodeType and not the child-nodes (or the opposite) you can specify the setting a little more:<br>
`includeNodeType`: hides or shows the nodes of the NodeType, has no effect on the child-nodes
`includeChildNodes`: hides or shows the child-nodes of the created node of that NodeType, has no effect on the NodeType

```yaml
nodeTypes:
'Foo.Bar:GridCollection':
includeNodeType: false # excludes only the NodeType
includeChildNodes: true # includes all child-nodes

'Foo.Bar:SelectionOptionCollection':
includeNodeType: true # includes only the NodeType
includeChildNodes: false # excludes all child-nodes
```
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ export default class PlaceholderInsertDropdown extends PureComponent {
if (!elementsNode) {
return null;
}
const options = elementsNode.children
.map(node => this.props.nodesByContextPath[node.contextPath])
.map(node => ({
value: node.properties.identifier || node.identifier,
label:
node.properties.label || node.properties.identifier || node.identifier
}));
const options = this.getOptionsRecursively(elementsNode.children);

if (options.length === 0) {
return null;
Expand All @@ -74,4 +68,62 @@ export default class PlaceholderInsertDropdown extends PureComponent {
/>
);
}

getOptionsRecursively(elements) {
const returnValues = [];
const nodeTypesSettings = this.props.inlineEditorOptions.nodeTypes;

elements.forEach((childNode) => {
const currentNode = this.props.nodesByContextPath[childNode.contextPath];
const childChildNodes = this.props.nodesByContextPath[childNode.contextPath].children;
let skipMode = 'includeAll';

if (nodeTypesSettings) {
if (nodeTypesSettings.hasOwnProperty(childNode.nodeType)) {
const nodeTypeSettings = nodeTypesSettings[childNode.nodeType];

if (typeof nodeTypeSettings === 'boolean') {
if (!nodeTypeSettings) {
// exclude all
return;
}
}
else if (nodeTypeSettings.hasOwnProperty('includeNodeType') || nodeTypeSettings.hasOwnProperty('includeChildNodes')) {
if (!nodeTypeSettings.includeNodeType && !nodeTypeSettings.includeChildNodes) {
// exclude all
return;
}
else if (!nodeTypeSettings.includeNodeType && nodeTypeSettings.includeChildNodes) {
// include only the child-nodes, the NodeType will be excluded
skipMode = 'includeChildren'
}
else if (nodeTypeSettings.includeNodeType && !nodeTypeSettings.includeChildNodes) {
// include only the NodeType
skipMode = 'includeParent'
}
}
}
}

if (skipMode === 'includeAll' || skipMode === 'includeParent') {
returnValues.push({
value: currentNode.properties.identifier || currentNode.identifier,
label:
currentNode.properties.label || currentNode.properties.identifier || currentNode.identifier
});
}

if (skipMode === 'includeAll' || skipMode === 'includeChildren') {
const childOptions = this.getOptionsRecursively(childChildNodes);

if (Array.isArray(childOptions)) {
childOptions.forEach(childOption => {
returnValues.push(childOption);
});
}
}
});

return returnValues;
}
}
Loading