Skip to content

Commit

Permalink
Implement HiddenFieldDefinitionBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Mar 6, 2024
1 parent f473638 commit dbc717c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.merkle.oss.magnolia.definition.builder.simple;

import info.magnolia.ui.field.HiddenFieldDefinition;

/**
* builds a {@link HiddenFieldDefinition}
* @see <a href="https://docs.magnolia-cms.com/product-docs/6.2/Developing/Templating/Dialog-definition/Field-definition/List-of-fields/Hidden-field.html">magnolia Docs - Hidden field </a>
* @author Merkle DACH
*/
public class HiddenFieldDefinitionBuilder<T> extends AbstractConfiguredFieldDefinitionBuilder<T, HiddenFieldDefinition<T>, HiddenFieldDefinitionBuilder<T>> {
public HiddenFieldDefinition<T> build(final String name, final Class<T> type) {
final HiddenFieldDefinition<T> definition = new HiddenFieldDefinition<>();
definition.setType(type);
super.populate(definition, name);
return definition;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.merkle.oss.magnolia.definition.builder.simple;

import com.merkle.oss.magnolia.definition.builder.AbstractFieldDefinitionBuilderTestCase;
import info.magnolia.ui.field.HiddenFieldDefinition;
import info.magnolia.ui.field.TextFieldDefinition;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class HiddenFieldDefinitionBuilderTest extends AbstractFieldDefinitionBuilderTestCase {
@Test
void testBuilder() {
final HiddenFieldDefinition<Integer> definition = super.assertField(new HiddenFieldDefinitionBuilder<>(), (name, builder) -> builder.build(name, Integer.class), 42)
.build("hidden", Integer.class);

final HiddenFieldDefinition<String> emptyDefinition = new HiddenFieldDefinitionBuilder<String>().build("hidden", String.class);
assertEquals(String.class, emptyDefinition.getType());
}
}

0 comments on commit dbc717c

Please sign in to comment.