Skip to content

Commit

Permalink
FEATURE: Create Setting for Placeholder-Insert
Browse files Browse the repository at this point in the history
- Create a frontend settings 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
    are not in the setting

Resolves: neos#99
  • Loading branch information
erkenes committed Mar 5, 2024
1 parent 8b4002c commit 2ba0811
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ Neos:
javascript:
"Neos.Form.Builder:PlaceholderInsert":
resource: '${"resource://Neos.Form.Builder/Public/JavaScript/PlaceholderInsert/Plugin.js"}'
frontendConfiguration:
'Neos.Form.Builder:PlaceholderInsert':
ignoreNodeTypesInDropdown:
'Neos.Form.Builder:Section': true
'Neos.Form.Builder:StaticText': true
'Neos.Form.Builder:ValidatorCollection': true
'Neos.Form.Builder:SelectOption': true
'Neos.Form.Builder:SelectOptionCollection': true
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,23 @@ 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, add the NodeType with the value `true` to the `ignoreNodeTypeInDropdown` setting.

To exclude all child NodeTypes of a NodeType, add the NodeType with the value `true` to the `ignoreChildNodeTypesInDropdown` setting.
```yaml
# Settings.yaml
Neos:
Neos:
Ui:
frontendConfiguration:
'Neos.Form.Builder:PlaceholderInsert':
ignoreNodeTypeInDropdown:
'Some.Package:HoneypotField': true
'Some.Package:Image': true
```
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const parentNodeContextPath = contextPath => {
i18nRegistry: globalRegistry.get("i18n"),
nodeTypeRegistry: globalRegistry.get(
"@neos-project/neos-ui-contentrepository"
)
),
frontendConfiguration: globalRegistry.get('frontendConfiguration')
}))

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

getOptionsRecursively(elements) {
const {frontendConfiguration} = this.props;
const ignoreNodeTypeInDropdown = frontendConfiguration.get('Neos.Form.Builder:PlaceholderInsert').ignoreNodeTypeInDropdown;
const ignoreAllChildNodesOfNodeTypeInDropdown = frontendConfiguration.get('Neos.Form.Builder:PlaceholderInsert').ignoreAllChildNodesOfNodeTypeInDropdown;
const returnValues = [];

elements.forEach((element) => {
const node = this.props.nodesByContextPath[element.contextPath];
if (!node) {
return null;
}

if (!(ignoreNodeTypeInDropdown.hasOwnProperty(node.nodeType) && ignoreNodeTypeInDropdown[node.nodeType] === true)) {
returnValues.push({
value: node.properties.identifier || node.identifier,
label: node.properties.label || node.properties.identifier || node.identifier
});
}

if (!(ignoreAllChildNodesOfNodeTypeInDropdown.hasOwnProperty(node.nodeType) && ignoreAllChildNodesOfNodeTypeInDropdown[node.nodeType] === true)) {
const childNodes = this.props.nodesByContextPath[element.contextPath].children;
const childOptions = this.getOptionsRecursively(childNodes);

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

return returnValues;
}
}
Loading

0 comments on commit 2ba0811

Please sign in to comment.