Skip to content

Commit

Permalink
Add rootPath to AssetLinkDefinitionBuilder and InternalLinkDefinition…
Browse files Browse the repository at this point in the history
…Builder
  • Loading branch information
eschleb committed Jun 17, 2024
1 parent adac0cb commit 3b8eb87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
package com.merkle.oss.magnolia.definition.builder.simple;

import info.magnolia.dam.api.Item;
import info.magnolia.dam.app.data.AssetDatasourceDefinition;
import info.magnolia.dam.app.field.DamLinkFieldDefinition;
import info.magnolia.ui.field.LinkFieldDefinition;

import javax.annotation.Nullable;

/**
* builds a {@link LinkFieldDefinition}
* @see <a href="https://docs.magnolia-cms.com/product-docs/6.2/Developing/Templating/Dialog-definition/Field-definition/List-of-fields/Link-field.html">magnolia Docs - Link field </a>
* @author Merkle DACH
*/
public class AssetLinkDefinitionBuilder extends AbstractLinkFieldDefinitionBuilder<Item, DamLinkFieldDefinition, AssetLinkDefinitionBuilder> {

@Nullable
private String rootPath;

public AssetLinkDefinitionBuilder() {}
public AssetLinkDefinitionBuilder(final DamLinkFieldDefinition definition) {
super(definition);
}

public DamLinkFieldDefinition build(final String name) {
final DamLinkFieldDefinition definition = new DamLinkFieldDefinition();
super.populate(definition, name, definition.getDatasource());
final AssetDatasourceDefinition datasource = (AssetDatasourceDefinition)definition.getDatasource();
datasource.setRootPath(rootPath);
super.populate(definition, name, datasource);
return definition;
}

public AssetLinkDefinitionBuilder rootPath(final String rootPath) {
this.rootPath = rootPath;
return self();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
package com.merkle.oss.magnolia.definition.builder.simple;

import info.magnolia.pages.app.field.PageLinkFieldDefinition;
import info.magnolia.ui.datasource.jcr.JcrDatasourceDefinition;
import info.magnolia.ui.field.LinkFieldDefinition;

import javax.annotation.Nullable;
import javax.jcr.Node;

public class InternalLinkDefinitionBuilder extends AbstractLinkFieldDefinitionBuilder<Node, LinkFieldDefinition<Node>, InternalLinkDefinitionBuilder> {

@Nullable
private String rootPath;

public InternalLinkDefinitionBuilder() {}
public InternalLinkDefinitionBuilder(final LinkFieldDefinition<Node> definition) {
super(definition);
}

public LinkFieldDefinition<Node> build(final String name) {
final PageLinkFieldDefinition definition = new PageLinkFieldDefinition();
super.populate(definition, name, definition.getDatasource());
final JcrDatasourceDefinition datasource = (JcrDatasourceDefinition)definition.getDatasource();
datasource.setRootPath(rootPath);
super.populate(definition, name, datasource);
return definition;
}

public InternalLinkDefinitionBuilder rootPath(final String rootPath) {
this.rootPath = rootPath;
return self();
}
}

0 comments on commit 3b8eb87

Please sign in to comment.