How can I get the item value from JCR for custom field factory in Magnolia version 6.2? In the earlier version of Magnolia, in Abstract FieldFactory implementations was the property Item item. Since version 6.2. it is no longer there.
public class CustomFieldFactory extends AbstractFieldFactory<String, CustomFieldDefinition> {
@Inject
public CustomFieldFactory(CustomFieldDefinition definition, ComponentProvider componentProvider) {
super(definition, componentProvider);
}
public Component createFieldComponent() {
Object field;
if (((CustomFieldDefinition)this.getDefinition()).getRows() > 1) {
TextArea textArea = new TextArea();
textArea.setRows(((SalesVolumeFromDataHubFieldDefinition)this.getDefinition()).getRows());
field = textArea;
} else {
field = new TextField();
}
if (((CustomFieldDefinition)this.getDefinition()).getMaxLength() != -1) {
((AbstractTextField)field).setMaxLength(((CustomFieldDefinition)this.getDefinition()).getMaxLength());
MaxLengthIndicatorExtension.extend((AbstractTextField)field);
}
((AbstractTextField)field).setPlaceholder(((CustomFieldDefinition)this.getDefinition()).getPlaceholder());
return (Component)field;
}
}
You can inject ValueContext<Node>
into the field factory constructor.
Then you can retrieve it via
Node dialogNode = valueContext.getSingleOrThrow();
Property thisFieldProperty = dialogNode.getProperty(getDefinition().getName());
Here is a test example.