oo

Hiding the Configuration UI

Liferay generates a configuration UI automatically after a configuration interface deploys. But you may have certain use cases where you want to hide the UI. For example, you don’t want an administrator to have access to a specific configuration or you want to hide the configuration based on certain criteria. To hide the configuration UI, you have two different options:

  • Use a generateUI annotation property
  • Use the configuration visibility interface

Using generateUI

If you want to hide the configuration UI under all circumstances, include the ExtendedObjectClassDefinition annotation property generateUI in your configuration interface. Set the property to false. Note that this hides the configuration UI for all scopes.

@ExtendedObjectClassDefinition(generateUI=false)

Using the Configuration Visibility Interface

Use the ConfigurationVisibilityController interface if you want to hide the configuration UI selectively.

See an Example Implementation

Start a new Liferay instance by running

docker run -it -m 8g -p 8080:8080 liferay/portal:7.4.3.112-ga112

Sign in to Liferay at http://localhost:8080. Use the email address test@liferay.com and the password test. When prompted, change the password to learn.

Then, follow these steps.

  1. Download and unzip Hiding the Configuration UI

    curl https://resources.learn.liferay.com/dxp/latest/en/building-applications/core-frameworks/configuration-framework/liferay-g8v3.zip -O
    
    unzip liferay-g8v3.zip
    
  2. From the module root, build and deploy.

    ./gradlew deploy -Ddeploy.docker.container.id=$(docker ps -lq)
    
    note

    This command is the same as copying the deployed jars to /opt/liferay/osgi/modules on the Docker container.

  3. Confirm the deployment in the Liferay Docker container console.

    STARTED com.acme.g8v3.impl_1.0.0 [1650]
    
  4. Open your browser to https://localhost:8080 and navigate to Control PanelConfigurationSystem Settings. Under Platform click Third Party. Click G8V3 Able Configuration on the left. Check the box for Enable G8V3 Baker Configuration. Click the Update button.

    Clicking the checkbox makes the other configuration UI visible

  5. Notice that when this checkbox is not enabled the G8V3 Baker Configuration is hidden.

Implement the Interface

Create the configuration visibility interface for your application.

@Component(
	property = "configuration.pid=com.acme.g8v3.internal.configuration.G8V3BakerConfiguration",
	service = ConfigurationVisibilityController.class
)
public class G8V3BakerConfigurationVisibilityController
	implements ConfigurationVisibilityController {

	@Override
	public boolean isVisible(
		ExtendedObjectClassDefinition.Scope scope, Serializable scopePK) {

		try {
			G8V3AbleConfiguration g8v3AbleConfiguration =
				_configurationProvider.getSystemConfiguration(
					G8V3AbleConfiguration.class);

			return g8v3AbleConfiguration.enableG8V3BakerConfiguration();
		}
		catch (ConfigurationException configurationException) {
			_log.error(configurationException, configurationException);

			return false;
		}
	}

	private static final Log _log = LogFactoryUtil.getLog(
		G8V3BakerConfigurationVisibilityController.class);

	@Reference
	private ConfigurationProvider _configurationProvider;

}

Identify the configuration interface with the @Component annotation. Note that the configuration.pid in the Component annotation must match the fully qualified class name of the configuration interface.

Write your own logic for the interface’s isVisible() method. The example project uses a simple logic to check the boolean setting of G8V3 Able Configuration. In your application, design your own programming logic to hide or show the configuration UI.