-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eschleb
committed
Apr 18, 2024
1 parent
99ab426
commit d7833d8
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ain/java/com/merkle/oss/magnolia/definition/custom/childnodewrapper/ChildNodeWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.merkle.oss.magnolia.definition.custom.childnodewrapper; | ||
|
||
import info.magnolia.ui.editor.EditorView; | ||
import info.magnolia.ui.editor.FormDefinition; | ||
import info.magnolia.ui.editor.FormView; | ||
import info.magnolia.ui.editor.ItemProviderDefinition; | ||
import info.magnolia.ui.editor.JcrChildNodeProviderDefinition; | ||
import info.magnolia.ui.field.ConfiguredComplexPropertyDefinition; | ||
import info.magnolia.ui.field.ConfiguredFieldDefinition; | ||
import info.magnolia.ui.field.EditorPropertyDefinition; | ||
import info.magnolia.ui.framework.layout.FieldLayoutDefinition; | ||
import info.magnolia.ui.framework.layout.SingleFieldLayoutProducer; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.jcr.Node; | ||
|
||
public class ChildNodeWrapper<T extends EditorPropertyDefinition> extends ConfiguredComplexPropertyDefinition<Node> implements FormDefinition<Node> { | ||
private final JcrChildNodeProviderDefinition nodeProvider = new JcrChildNodeProviderDefinition(); | ||
private final String name; | ||
private final T field; | ||
|
||
public ChildNodeWrapper(final String nodeName, final T field) { | ||
this.field = field; | ||
this.name = nodeName + "." + field.getName(); | ||
this.nodeProvider.setSupportI18N(false); | ||
this.nodeProvider.setNodeName(nodeName); | ||
} | ||
|
||
public T getField() { | ||
return field; | ||
} | ||
|
||
@Override | ||
public Class<? extends EditorView<Node>> getImplementationClass() { | ||
return (Class) FormView.class; | ||
} | ||
|
||
@Override | ||
public boolean isI18n() { | ||
return field.isI18n(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public ItemProviderDefinition<Node, Node> getItemProvider() { | ||
return nodeProvider; | ||
} | ||
|
||
@Override | ||
public List<EditorPropertyDefinition> getProperties() { | ||
return List.of(field); | ||
} | ||
|
||
@Override | ||
public FieldLayoutDefinition<SingleFieldLayoutProducer> getLayout() { | ||
return new SingleFieldLayoutProducer.Definition(); | ||
} | ||
|
||
public static List<EditorPropertyDefinition> wrap(final String nodeName, final ConfiguredFieldDefinition<?>... fields) { | ||
return wrap(nodeName, Arrays.stream(fields)).collect(Collectors.toList()); | ||
} | ||
public static List<EditorPropertyDefinition> wrap(final String nodeName, final List<ConfiguredFieldDefinition<?>> fields) { | ||
return wrap(nodeName, fields.stream()).collect(Collectors.toList()); | ||
} | ||
|
||
public static Stream<EditorPropertyDefinition> wrap(final String nodeName, final Stream<ConfiguredFieldDefinition<?>> fields) { | ||
return fields.map(field -> new ChildNodeWrapper<>(nodeName, field)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../main/java/com/merkle/oss/magnolia/definition/custom/childnodewrapper/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ChildNodeWrapper | ||
Allows to save fields in child nodes without being nested in a composite/switchable field. | ||
|
||
<img alt="screenshot" src='assets/screenshot.png' width='500'> | ||
<br> | ||
<img alt="jcr-structure" src='assets/jcr_structure.png' width='1000'> | ||
|
||
## Usage | ||
### Dialog | ||
|
||
```java | ||
import info.magnolia.ui.field.EditorPropertyDefinition; | ||
import info.magnolia.module.blossom.annotation.TabFactory; | ||
|
||
import com.merkle.oss.magnolia.definition.custom.childnodewrapper.ChildNodeWrapper; | ||
|
||
@TabFactory("someTab") | ||
public List<EditorPropertyDefinition> someTab() { | ||
return ChildNodeWrapper.wrap("teaser", | ||
new TextFieldDefinitionBuilder().i18n().build("title"), | ||
new TextFieldDefinitionBuilder().i18n().build("text"), | ||
new AssetLinkDefinitionBuilder().build("image") | ||
); | ||
} | ||
``` |
Binary file added
BIN
+11.4 KB
...merkle/oss/magnolia/definition/custom/childnodewrapper/assets/jcr_structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.8 KB
...om/merkle/oss/magnolia/definition/custom/childnodewrapper/assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.