Liferay Object Management

Manage the mapping and definitions for Liferay objects

Liferay Objects can generate service layers by simply declaring schema in the Liferay control panel. Liferay makes the Object's content accessible via headless APIs as well. On Notifications with Liferay Objects, I've already written one blog post. I'll go over the fundamentals of objects, mappings, and Layouts in greater depth.

 

 

Create Objects

Go to Liferay's control panel and select Objects to create new Liferay objects.

When you click the "Add Object" button, you will be prompted to enter a name for the item. Once finished, click the Save button to create a draft object.

This is able to be edited, and fields could be added to the object.

Liferay will include certain default fields, like "Create Date," "Status," and others. Also, this panel itself lets you define new fields.

These are some of the field types that Liferay objects may support.

You can publish your object once you have finished with the field definitions. But wait for a second…

Choose the object's scope. Since once it is published, it cannot be changed

Publish it now, and boom. For this item, Liferay has developed service layers, a database table, and a REST API.

 

Manage Object Entries

The object is now available in the portal category you have chosen (in our example, Control Panel > Users and Organizations).

You can manage the entries in these objects from this page.

 

Access Object Headless APIs

The /o/api page provides access to Liferay objects' headless APIs. where Section /o/objectName shall contain all APIs linked to the object.

GraphQL Query to fetch the object entries

{
  c{
    employee(employeeId:10231){
      employeeId
      emailAddress
      firstName
      lastName
    }
    employees(page:1, pageSize:10){
      items{
         employeeId
      emailAddress
      firstName
      lastName
      }
    }
  }
}

 

 

 

Mapping Between Objects

We will do a one-to-many mapping between Employee and Phone in this example. The quick steps are listed below.

  • Navigate to edit the “Employee” page

  • Open the “Relationship” tab, and click on “Add Relationship”

  • Enter the required details

Click on the save button.

It will add a new field with the name "classPK" to the object "Phone."

Let's define Layout in the object now so that mapping can be seen more clearly.

Add one entry to the Employee object now.

After you are finished, click the save button. Liferay will then update the screen's layout to show the contact information that was previously established in the layout, from which you can see the mapped "Phone" entities.

The most recent version of Liferay will let you add mapping entries right here.

The blog would be extremely long if I listed all the intriguing things we can do with Liferay objects. Let's discuss those in the next blog.