Type aliases

The $type property allows developers to use easy-to-remember shortcuts for definition classes in YAML definitions instead of fully classified Java class names.

Overriding a type or class

If you inherit or decorate a definition, you might need to override the original type or class. You do not need to worry when overriding a type with another type or a class with another class. However, be careful when overriding a type with a class because there is no type for the class you want to use and vice versa.

/moduleA/dialogs/myDialog.yaml
properties:
  myField:
    $type: textField
  anotherField:
    class: info.magnolia.ui.field.ComboBoxFieldDefinition

Overriding the whole field

/moduleB/decorations/moduleA/dialogs/myDialog.properties.yaml
myField: !override #everything from the original definition is removed
  $type: myTextField
  #class: my.text.field #this would work as well

Overriding a type with a class (class takes precedence)

/moduleB/decorations/moduleA/dialogs/myDialog.properties.myField.yaml
class: my.text.field

Overriding a class with a class

/moduleB/decorations/moduleA/dialogs/myDialog.properties.anotherField.yaml
#$type: myComboBoxField #this would not work (class has always precedence)
class: my.comboBox.field

Introducing a type to a class

@FieldType("myTextField")
MyTextFieldDefinition extends TextFieldDefinition {}
/moduleB/decorations/moduleA/dialogs/myDialog.yaml
$type: myTextField

Custom aliases

Introducing type annotation to a custom type

import info.magnolia.config.resolver.TypeAlias;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@TypeAlias(type = MyDefinitionInterface.class)
public @interface MyDefinitionType {
    String value();
}

Annotating definition implementations

@MyDefinitionType("myDefinitionImplementation")
public class MyDefinitionImplementation implements MyDefinition {}
SomeDefinition.yaml
$type: myDefinitionImplementation
Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules