Portal: How to add a create button
In this How to, we use the CreateBrick to add a quick request button.
- How to add a create button
- How To
- Administrator, Integrator, Developer
- Portal, Customization
- iTop version:
What you will need to:
Know how to make an iTop extension and upgrade your system,
Have an iTop system with the demo data and the enhanced portal installed,
Have access to an account with enough rights to connect to the portal (usually this means having the
Aim of this tutorial
In this tutorial, you will learn how to:
Add a brick to the default portal
Use the CreateBrick brick to make a button opening a creation form anywhere in the portal
Step by step instructions
Creating the extension
First, we need to create an iTop extension that will alter the portal XML configuration to add a new brick. Check the Extension modules part from the customization guide (iTop Customization) if necessary.
Name the extension as sample-portal-add-button.
Remove the main.sample-portal-add-button.php file as we won't need any PHP code.
Changing the portal configuration
Now that we have the extension, we just need to make an XML delta and change the portal configuration to add the brick. Open the datamodel.sample-portal-add-button.xml file and paste the following code:
<?xml version="1.0" encoding="UTF-8"?> <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <module_designs> <module_design id="itop-portal" xsi:type="portal"> <bricks> <brick id="quick-new-user-request" xsi:type="Combodo\iTop\Portal\Brick\CreateBrick" _delta="define"> <active>true</active> <rank> <default>70</default> </rank> <width>4</width> <modal>true</modal> <title> <default>Brick:Portal:QuickNewUserRequest:Title</default> </title> <visible> <home>false</home> </visible> <decoration_class> <default>fa fa-bolt fa-2x fa-fw</default> </decoration_class> <!-- Class that will be create created with the form --> <class>UserRequest</class> <rules> <rule id="contact-to-userrequest"/> </rules> </brick> </bricks> </module_design> </module_designs> </itop_design>
This adds a brick to the portal that will :
Be placed after the other bricks in both the home page and the navigation menu as its rank is greater than those from other bricks.
Not be displayed on the home page.
Open the form in a modal dialog instead of redirecting to a whole page.
Make a form to create a object of class UserRequest.
With some presets from the contact-to-userrequest action rule.
Dictionary entry for the label of the button
Edit the file
to add an entry for the label of the button, as shown below:
<?php Dict::Add('EN US', 'English', 'English', array( 'Brick:Portal:QuickNewUserRequest:Title' => 'Quick new request', ));
You can repeat the same operation for other languages.
Upgrading the system
Finally run an upgrade of your iTop system with the new extension option checked and access the portal. You should see the new Quick new request button on the navigation menu. Click it and a creation form will open.
The main difference with the default UserRequest creation process is that you don't have to go through the services catalog to choose the ServiceSubcategory; allowing you to create objects from anywhere in the portal.
You can find this extension with some example themes here: sample-portal-add-button-1.0.0-145.zip