Search code examples
liferayliferay-7

Custom email sent by Liferay Form


I'm trying to override the email-notification sent out by Liferay Form. I've followed the tricks in this topic: https://community.liferay.com/it/forums/-/message_boards/view_message/104934134. No dice. I've succesfully added a custom implementation of DDLFormEmailNotificationSender. Which is registered correctly, (with correct service). If I check out the registered service, My custom DDLFormEmailNotificationSender comes out on top. But when I submit a form, liferay keeps using the 'normal' DDLFormEmailNotificationSender, and not my custom DDLFormEmailNotificationSender. Any tips 'n tricks?

My DDLFormEmailNotificationSender looks like this:

@Component(
    immediate = true,
    property = {
            "service.ranking:Integer=100"
    },
    service = DDLFormEmailNotificationSender.class
)
public class CustomDDLFormEmailNotificationSender extends DDLFormEmailNotificationSender {

    private static final String CUSTOM_TEMPLATE_PATH = "";

    @Override
    protected Template createTemplate(
        PortletRequest portletRequest, DDLRecordSet recordSet,
        DDLRecord record) throws PortalException {

        Template template = TemplateManagerUtil.getTemplate(TemplateConstants.LANG_TYPE_SOY,
        getTemplateResource(CUSTOM_TEMPLATE_PATH), false);

        populateParameters(template, portletRequest, recordSet, record);

        return template;
    }
}

(I know the CUSTOM_TEMPLATE_PATH is empty right now. But that's only for testing purposes.

I've created a fragment to expose the private package as described in the forum post:

Bundle-Name: liferay-xxx-dynamic-data-lists-form-override
Bundle-SymbolicName: liferay.xxx.dynamic.data.lists.form.override
Fragment-Host: com.liferay.dynamic.data.lists.form.web;bundle-version="2.0.15"

Export-Package: com.liferay.dynamic.data.lists.form.web.internal.notification
-jsp: *.jsp,*.jspf
-plugin.jsp: com.liferay.ant.bnd.jsp.JspAnalyzerPlugin
-plugin.resourcebundle: com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin
-plugin.sass: com.liferay.ant.bnd.sass.SassAnalyzerPlugin
-sass: *

So you can see I've exposed the "com.liferay.dynamic.data.lists.form.web.internal.notification" package.

If I check the DDLFormEmailNotificationSender in Apache GOGO:

services | grep DDLFormEmailNotificationSender
{com.liferay.dynamic.data.lists.form.web.internal.notification.DDLFormEmailNotificationSender}={service.ranking=100, component.name=be.xxx.portal.website.form.CustomDDLFormEmailNotificationSender, component.id=519, service.id=299, service.bundleid=757, service.scope=bundle}
{com.liferay.dynamic.data.lists.form.web.internal.notification.DDLFormEmailNotificationSender}={component.name=com.liferay.dynamic.data.lists.form.web.internal.notification.DDLFormEmailNotificationSender, component.id=811, service.id=2629, service.bundleid=143, service.scope=bundle}
true

I'm on Liferay 7.0.


Solution

  • I've got some support from the Liferay Community, and found out how to fix it.

    Above configuration is correct! But, the (liferay)service referencing the DDLFormEmailNotification, has this reference static / reluctant. I had to create a config file to drop in my osgi/configs folder, which defines the correct implementation. (My CustomDDLFormEmailNotificationSender).

    My config file is named: com.liferay.dynamic.data.lists.form.web.internal.portlet.action.AddRecordMVCActionCommand.config

    This is because I need to configure the AddRecordMVCAction command. (Configure references that are defined there as static / reluctant).

    It contains:

    DDLFormEmailNotificationSender.target="(component.name\=be.xxx.portal.website.form.CustomDDLFormEmailNotificationSender)"
    

    So basicly it says: DDLFormEmailNotificationSender (is the reference name there), should be: be.xxx.portal.website.form.CustomDDLFormEmailNotificationSender.

    Make sure that component is deployed correctly, because once configured, there is no fallback to the original implementation. (If you remove that configuration, osgi will fallback).

    Source: https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-0/overriding-service-references#find-the-component-and-service-reference

    Hope this helps someone.