Message Boards

Can the resource importer create layouts of type url or link_to_layout?

thumbnail
Wouter Vernaillen, modified 8 Years ago.

Can the resource importer create layouts of type url or link_to_layout?

Junior Member Posts: 80 Join Date: 6/6/09 Recent Posts
Is it possible to create layouts of type 'url' or 'link_to_layout' with the resource importer?
What would be the syntax to use in sitemap.json?

I tried many different parameters, like the example below, but with no success. The resource importer is always creating the layout with type 'portlet'.

{
    "friendlyURL": "/linkToUrl",
    "name": "Link to URL",
    "title": "Link to URL",
    "type": "url",
    "url": "/otherUrl"
},
{
    "friendlyURL": "/linkToPage",
    "name": "Link to Page",
    "title": "Link to Page",
    "type": "link_to_layout",
    "linkToLayoutId": "16"
}
thumbnail
Andew Jardine, modified 8 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Wouter,

I don't think that this is currently supported. It's been a few months since I checked out the source code so it may have been added but I doubt it. The repo can be found here fo ryou to have a look https://github.com/liferay/liferay-plugins/tree/master/webs/resources-importer-web

I know that you can specify typeSettings for some things (maybe a layout as well?). If you can do it for the layouts then that iw where I suspect you would need to set those values.
thumbnail
Andew Jardine, modified 8 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
I stand corrected. Check out this URL --

https://github.com/liferay/liferay-plugins/blob/master/webs/resources-importer-web/docroot/WEB-INF/src/com/liferay/resourcesimporter/util/FileSystemImporter.java

which has an addLayout method where you can see the properties of the JSON. One of the ones it checks is in fact type. That is the logic you want to reference I think.


protected void addLayout(
			boolean privateLayout, long parentLayoutId,
			JSONObject layoutJSONObject)
		throws Exception {

		if (targetClassName.equals(LayoutSetPrototype.class.getName())) {
			privateLayout = true;
		}

		Map<locale, string> nameMap = getMap(layoutJSONObject, "name");
		Map<locale, string> titleMap = getMap(layoutJSONObject, "title");

		String type = layoutJSONObject.getString("type");

		if (Validator.isNull(type)) {
			type = LayoutConstants.TYPE_PORTLET;
		}

		String typeSettings = layoutJSONObject.getString("typeSettings");

		boolean hidden = layoutJSONObject.getBoolean("hidden");

		Map<locale, string> friendlyURLMap = new HashMap&lt;&gt;();

		String friendlyURL = layoutJSONObject.getString("friendlyURL");

		if (Validator.isNotNull(friendlyURL) &amp;&amp;
			!friendlyURL.startsWith(StringPool.SLASH)) {

			friendlyURL = StringPool.SLASH + friendlyURL;
		}

		friendlyURLMap.put(LocaleUtil.getDefault(), friendlyURL);

		ServiceContext serviceContext = new ServiceContext();

		serviceContext.setCompanyId(companyId);
		serviceContext.setScopeGroupId(groupId);
		serviceContext.setUserId(userId);

		ServiceContextThreadLocal.pushServiceContext(serviceContext);

		try {
			String layoutPrototypeName = layoutJSONObject.getString(
				"layoutPrototypeName");

			String layoutPrototypeUuid = null;

			if (Validator.isNotNull(layoutPrototypeName)) {
				LayoutPrototype layoutPrototype = getLayoutPrototype(
					companyId, layoutPrototypeName);

				layoutPrototypeUuid = layoutPrototype.getUuid();
			}
			else {
				layoutPrototypeUuid = layoutJSONObject.getString(
					"layoutPrototypeUuid");
			}

			if (Validator.isNotNull(layoutPrototypeUuid)) {
				boolean layoutPrototypeLinkEnabled = GetterUtil.getBoolean(
					layoutJSONObject.getString("layoutPrototypeLinkEnabled"),
					false);

				serviceContext.setAttribute(
					"layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

				serviceContext.setAttribute(
					"layoutPrototypeUuid", layoutPrototypeUuid);
			}

			Layout layout = LayoutLocalServiceUtil.addLayout(
				userId, groupId, privateLayout, parentLayoutId, nameMap,
				titleMap, null, null, null, type, typeSettings, hidden,
				friendlyURLMap, serviceContext);

			LayoutTypePortlet layoutTypePortlet =
				(LayoutTypePortlet)layout.getLayoutType();

			String layoutTemplateId = layoutJSONObject.getString(
				"layoutTemplateId", _defaultLayoutTemplateId);

			if (Validator.isNotNull(layoutTemplateId)) {
				layoutTypePortlet.setLayoutTemplateId(
					userId, layoutTemplateId, false);
			}

			JSONArray columnsJSONArray = layoutJSONObject.getJSONArray(
				"columns");

			addLayoutColumns(
				layout, LayoutTypePortletConstants.COLUMN_PREFIX,
				columnsJSONArray);

			LayoutLocalServiceUtil.updateLayout(
				groupId, layout.isPrivateLayout(), layout.getLayoutId(),
				layout.getTypeSettings());

			JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray(
				"layouts");

			addLayouts(privateLayout, layout.getLayoutId(), layoutsJSONArray);
		}
		catch (Exception e) {
			if (_log.isWarnEnabled()) {
				_log.warn("Unable to import layout " + layoutJSONObject, e);
			}

			throw e;
		}
		finally {
			ServiceContextThreadLocal.popServiceContext();
		}
	}
</locale,></locale,></locale,>
thumbnail
Wouter Vernaillen, modified 8 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Junior Member Posts: 80 Join Date: 6/6/09 Recent Posts
Hey Andew, I'm sorry for the very late reply. I've been off from work.

Apparently the support for other layout types has been added in Liferay 7, but is not available yet in the Liferay 6.2 releases.
We're running 6.2 ga2, so we're not able to use other layout types then portlet.

FYI, this is the ticket: LPS-50735 and the commit
thumbnail
Andew Jardine, modified 8 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Wouter,

Just for kicks, I would clone the 7 report, build the plugin and see if it works on 6.2. Slim chance I imagine but worth the 20 minutes worth of effort to see if you can be "ahead of the pack". Alternatively, you could fork the 6.2 one and merge in the commits to make this work.
thumbnail
Travis Cory, modified 8 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Junior Member Posts: 73 Join Date: 6/4/13 Recent Posts
Here are the layout types from portal properties

    #
    # Set the list of layout types. The display text of each of the layout types
    # is set in content/Language.properties and prefixed with "layout.types.".
    #
    # You can create new layout types and specify custom settings for each
    # layout type. End users input dynamic values as designed in the edit page.
    # End users see the layout as designed in the view page. The generated
    # URL can reference properties set in the edit page. Parentable layouts
    # can contain child layouts. You can also specify a comma delimited list of
    # configuration actions that will be called for your layout when it is
    # updated or deleted.
    #
    layout.types=portlet,panel,embedded,url,link_to_layout


you should be able to use link_to_layout
thumbnail
Aravinth Kumar, modified 3 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Regular Member Posts: 152 Join Date: 6/26/13 Recent Posts
HI All,Is the type "URL" available in liferay 7.x versions resource importer. I m seeing below link has type:"url" but its not working. Please confirm.
[code]        {
            "friendlyURL": "/url-page",
            "name": "URL Page",
            "title": "URL Page",
            "type": "url"
        }
https://help.liferay.com/hc/en-us/articles/360017883012-Importing-Resources-with-a-Theme
Thanks in Advance.
thumbnail
Aravinth Kumar, modified 3 Years ago.

RE: Can the resource importer create layouts of type url or link_to_layout?

Regular Member Posts: 152 Join Date: 6/26/13 Recent Posts
Hi All, 
We can achieve that through typesettings.
"type":"url",
"typeSettings":"url=https://www.liferay.com"

Regards,
Aravinth