Skip to content
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
14 changes: 13 additions & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ 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
ContentRepositoryRegistry:
presets:
'default':
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,33 @@ 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
```

## Upgrade to version 3

### Neos.Form.Builder:SelectOptionCollection
The `Neos.Form.Builder:SelectOptionCollection` prototype has been changed and uses now `items` instead of `collection`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,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 @@ -73,4 +90,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;
}
}
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/PlaceholderInsert/Plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading