Hello,
we have developed some space blueprints. Each blueprint has some children pages. We want to set labels on these pages (automatically when the space and the corresponding pages are created).
Anyone knows how? Or if at all possible? I tried index-key (<space-blueprint key="xx" i18n-name-key="confluence.blueprints.space.xx" category="yy" index-key="testlabel">) but it doesn't seem to have any effect whatsoever.
Thanks for any tips in advance!
Community moderators have prevented the ability to post new answers.
Just adding some code to @Robert Reiner [smartics] solution.
One can really use the event listeners to achieve this:
@EventListener public void pageCreatedEvent(PageCreateEvent event) { log.debug("Page created event:%s", event.getPage().getTitle()); if (event.getPage().getTitle().equalsIgnoreCase("<put-in-your-page-title>")) { labelManager.addLabel((Labelable) event.getPage(), new Label("<put-in-your-label")); } }
The labelManager
is injected automatically. Just put a field in your event class like this:
public class MyAnnotatedEventListener implements InitializingBean, DisposableBean { private static final Logger log = LoggerFactory.getLogger(MyAnnotatedEventListener.class); protected EventPublisher eventPublisher; protected PageManager pageManager; protected ThemeManager themeManager; protected LabelManager labelManager; ...
And register you event class in atlassian-config.xml:
<component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher"/> <component-import key="themeManager" interface="com.atlassian.confluence.themes.ThemeManager"/> <component-import key="labelManager" interface="com.atlassian.confluence.labels.LabelManager"/> <component name="My Annotated Event Listener" key="annotatedEventListener" class="de.my.package.MyAnnotatedEventListener"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Robert! Should I put the method (onPageCreate) in the corresponding ContextProvider class? And how can I pass on the labels in the .soy template? Thank you in advance!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have written a Listener, but I assume the ContextProvider would work, too. You may add additional input fields to your soy: ... <form> ... <input type="hidden" name="mykey" value="mayvalue" /> ... These should appear in the context (event or context provider): context.get("mykey").
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just in case: Listener @EventListener public void onXyzEvent(final XyzEvent event) { ... }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I could not manage this with configuration. So I added a listener to listen for events.
Here is some pseudocode (for a space label, but for pages this would be similar):
protected void onPageCreate(final ...Event event) { final SpaceBlueprint spaceBlueprint = event.getSpaceBlueprint(); final String moduleKey = spaceBlueprint.getModuleCompleteKey(); if (getModuleKey().equals(moduleKey)) { // determine if applicable final Space space = event.getSpace(); final String label = getLabel(); // determine Label to set if (!hasLabel(space, label)) { labelManager.addLabel(space, label); } } }
Register listener with the atlassian-plugin.xml:
<listener key="PageLabelListener" class="com.myorg.PageLabelListener" />
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.