Page tree
Skip to end of metadata
Go to start of metadata

Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 92 rates

To use Blossom style dialogs with the Data module you need to use an extension module called magnolia-module-blossom-extension-data. It adds a new annotation @DataTypeDialogFactory which is used exactly like @DialogFactory. Dialogs using this annotation will have the DataSaveHandler by default which is required for some of the controls used with the data module.

Note that dialogs for the types in the Data module need to have the same name as the type their intended to be used for.

The Blossom Extension Data Module requires Data Module 1.6.4 and Blossom 1.2.3.

import info.magnolia.module.blossom.annotation.TabFactory;
import info.magnolia.module.blossom.dialog.TabBuilder;
import info.magnolia.module.blossom.extension.data.DataTypeDialogFactory;

@DataTypeDialogFactory("category")
public class CategoryDialog {
 
    @TabFactory("Settings")
    public void settingsTab(TabBuilder tab) {
        tab.addEdit("name", "Name", "");
        tab.addEdit("maxResults", "Max results", "");
    }
}

Add dependencies to your pom.xml:

For setting up your settings.xml to use the magnolia repositories see these instructions.

    <dependency>
      <groupId>info.magnolia</groupId>
      <artifactId>magnolia-module-blossom-extension-data</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>info.magnolia</groupId>
      <artifactId>magnolia-module-data</artifactId>
      <version>1.7</version>
    </dependency>

For Blossom 1.2.x use:

  <dependency>
    <groupId>info.magnolia</groupId>
    <artifactId>magnolia-module-blossom-extension-data</artifactId>
    <version>1.0</version>
  </dependency>
  <dependency>
    <groupId>info.magnolia</groupId>
    <artifactId>magnolia-module-data</artifactId>
    <version>1.6.4</version>
  </dependency>

Configure the dialog exporter in blossom-servlet.xml:

Add the DataDialogExporter which will detect beans annotated with @DataTypeDialogFactory and expose them to Magnolia.

  <bean class="info.magnolia.module.blossom.extension.data.DataDialogExporter" />

If you're using class path scanning you will want to include the DataTypeDialogFactory annotation:

  <context:component-scan base-package="info.magnolia.blossom.sample" use-default-filters="false">
    ...
    <context:include-filter type="annotation" expression="info.magnolia.module.blossom.extension.data.DataTypeDialogFactory"/>
  </context:component-scan>

Notes

When you add a node type in AdminCentral a new node type is added, a menu item is added to the Data section (you need to reload to see it), and a new dialog is created. You need to delete or rename this dialog because it will have the same name as the dialog you're defining using blossom. If you already have the blossom dialog when you do this step then you will need to restart before it can be used. Blossom dialogs are only detected on startup and it has now been replaced by the dialog added to the repository.

When using files you should be using the 'dataFile' control rather than the 'file' control.

Using DataUUIDMultiSelect in paragraphs

When you want to select multiple items from the data module and save the references to them using UUIDs you need to use the DataSaveHandler. This is an example of how its done:

  @InitSaveHandler
  public SaveHandler initSaveHandler() {
    return new DataSaveHandler();
  }

  @TabFactory("Content")
  public void addDialog(TabBuilder tab) {
    tab.addFckEditor("body", "Text", "");
    DataUUIDMultiSelect data = (DataUUIDMultiSelect) tab.addControl("dataUUIDMultiSelect", "teasers", "Teasers", "Choose teasers");
    data.setRequired(true);
    data.setConfig("tree", "data");
    data.setConfig("repository", "data");
  }

  @RequestMapping("/text")
  public String render(Content paragraph) throws RepositoryException {

    HierarchyManager hm = MgnlContext.getHierarchyManager("data");
    for (Object teaserUuid : DataUtil.getMultiValues(paragraph, "teasers")) {
      Content teaserContent = hm.getContentByUUID(((String)teaserUuid));
      System.out.println(teaserContent.getUUID() + " :: " + teaserContent.getHandle());
    }
    return "text";
  }
}