Skip to content

Commit

Permalink
FEATURE: Create Mixin for Placeholder-Insert
Browse files Browse the repository at this point in the history
- Create a Mixin by which Form-Elements are shown in the placeholder insert
- Load all form-elements recursively
- Check if the elements are allowed to shown in the Placeholder-Insert-Dropdown
   by checking if they have the PlaceholderInsert-Mixin.

Resolves: #99
  • Loading branch information
erkenes committed Mar 4, 2024
1 parent 8b4002c commit 1336c11
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 9 deletions.
1 change: 1 addition & 0 deletions Configuration/NodeTypes.FormElement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'Neos.Form.Builder:LabelMixin': true
'Neos.Form.Builder:DefaultValueMixin': true
'Neos.Form.Builder:RequiredCheckboxMixin': true
'Neos.Form.Builder:Mixin.PlaceholderInsert': true
constraints:
nodeTypes:
'*': false
Expand Down
1 change: 1 addition & 0 deletions Configuration/NodeTypes.FormElements.Section.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'Neos.Form.Builder:IdentifierMixin': false
'Neos.Form.Builder:DefaultValueMixin': false
'Neos.Form.Builder:RequiredCheckboxMixin': false
'Neos.Form.Builder:Mixin.PlaceholderInsert': false
ui:
label: 'Section'
icon: 'icon-folder-open'
Expand Down
1 change: 1 addition & 0 deletions Configuration/NodeTypes.FormElements.StaticText.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'Neos.Form.Builder:IdentifierMixin': false
'Neos.Form.Builder:DefaultValueMixin': false
'Neos.Form.Builder:RequiredCheckboxMixin': false
'Neos.Form.Builder:Mixin.PlaceholderInsert': false
ui:
label: 'Static text'
icon: 'icon-align-left'
Expand Down
2 changes: 2 additions & 0 deletions Configuration/NodeTypes.Mixin.PaceholderInsert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'Neos.Form.Builder:Mixin.PlaceholderInsert':
abstract: true
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,15 @@ selectable:
}
}
```

## Example: Allow specific NodeTypes in the Placeholder-Insert

By default, all Form-Element NodeTypes are visible in the Placeholder-Insert (except StaticText and Section).

If you want to hide specific Form-Elements from the Placeholder-Insert then just disable the superType.

```yaml
'Some.Package.Builder:Element.HiddenInInsert':
superTypes:
'Neos.Form.Builder:Mixin.PlaceholderInsert': false
```
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const parentNodeContextPath = contextPath => {
"@neos-project/neos-ui-contentrepository"
)
}))

export default class PlaceholderInsertDropdown extends PureComponent {
handleOnSelect = value => {
this.props.executeCommand("placeholderInsert", value);
Expand All @@ -48,13 +49,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 +69,33 @@ export default class PlaceholderInsertDropdown extends PureComponent {
/>
);
}

getOptionsRecursively(elements) {
const {nodeTypeRegistry} = this.props;
const returnValues = [];


elements.forEach((element) => {
const node = this.props.nodesByContextPath[element.contextPath];
const childNodes = this.props.nodesByContextPath[element.contextPath].children;

if (nodeTypeRegistry.isOfType(node.nodeType, 'Neos.Form.Builder:Mixin.PlaceholderInsert')) {
returnValues.push({
value: node.properties.identifier || node.identifier,
label:
node.properties.label || node.properties.identifier || node.identifier
});
}

const childOptions = this.getOptionsRecursively(childNodes);

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

return returnValues;
}
}
330 changes: 329 additions & 1 deletion Resources/Public/JavaScript/PlaceholderInsert/Plugin.js

Large diffs are not rendered by default.

This file was deleted.

0 comments on commit 1336c11

Please sign in to comment.