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: Show all form fields in Placeholder-Insert #128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ Neos:
javascript:
"Neos.Form.Builder:PlaceholderInsert":
resource: '${"resource://Neos.Form.Builder/Public/JavaScript/PlaceholderInsert/Plugin.js"}'
frontendConfiguration:
'Neos.Form.Builder:PlaceholderInsert':
# ignore node types in dropdown
ignoreNodeTypeInDropdown:
'Neos.Form.Builder:Section': true
'Neos.Form.Builder:StaticText': true
'Neos.Form.Builder:ElementCollection': true
'Neos.Form.Builder:SelectOptionCollection': true
'Neos.Form.Builder:ValidatorCollection': true
# ignore all child nodes of node type in dropdown
ignoreAllChildNodesOfNodeTypeInDropdown:
'Neos.Form.Builder:SelectOptionCollection': true
'Neos.Form.Builder:ValidatorCollection': true
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,28 @@ 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':
# ignore node types in dropdown
ignoreNodeTypeInDropdown:
'Some.Package:HoneypotField': true
'Some.Package:Image': true
'Some.Package:Gallery': true
# ignore all child nodes of a node type in dropdown
ignoreAllChildNodesOfNodeTypeInDropdown:
'Some.Package:GalleryCollection': true
```
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,48 @@ 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);
};

render() {
let options = [];

const [formPath, workspace] = parentNodeContextPath(
parentNodeContextPath(this.props.focusedNode.contextPath)
).split("@");

// get options of first page
const elementsPath = `${formPath}/elements@${workspace}`;

const elementsNode = this.props.nodesByContextPath[elementsPath];
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 firstPageOptions = this.getOptionsRecursively(elementsNode.children);
if (firstPageOptions && firstPageOptions.length > 0) {
options = options.concat(firstPageOptions);
}

// get options of further pages
const furtherPagesPath = `${formPath}/furtherpages@${workspace}`;
const furtherPagesNode = this.props.nodesByContextPath[furtherPagesPath];
if (furtherPagesNode && furtherPagesNode.children && furtherPagesNode.children.length > 0) {
furtherPagesNode.children.forEach(furtherPageChildren => {
if (furtherPageChildren) {
const pageOptions = this.getOptionsOfPage(furtherPageChildren);

if (pageOptions && pageOptions.length > 0) {
options = options.concat(pageOptions);
}
}
});
}

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

getOptionsOfPage(page) {
const [path, workspace] = page.contextPath.split("@");
const elementsPath = `${path}/elements@${workspace}`;
const elementsNode = this.props.nodesByContextPath[elementsPath];
if (!elementsNode) {
return null;
}

return this.getOptionsRecursively(elementsNode.children);
}

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