Configuration
The first step in developing the module is to define the configuration data.
Configuration data is located in config.php file in the module.
return [
'created_at' => 1561714288,
'meta' => [
'name' => "SampleAddon",
'version' => '1.0',
'author' => 'Your name goes here',
'opening-type' => 'normal',
],
'show_on_adminArea' => true,
'show_on_clientArea' => true,
'status' => false,
'access_ps' => [],
'settings' => [],
];
Name | Type | Description |
created_at | Unix Time Stamp | Unix time stamp of date of completion of module |
meta/name | String | Name of the Module |
meta/version | String | Number | Float | Version Number of Module |
meta/author | String | Name of Developer of Module |
meta/opening-type | String | It specifies the opening style when "Settings" button is cliecked in add-ons page. Possible Values: - normal : Hides all other add-ons and configuration settings is opened. - modal : Shows configuration settings of add-on in modal. |
show_on_adminArea | Boolean | If the status of addon is activated, it will be visible on menu under "Tools > Addons" |
show_on_clientArea | Boolean | If the status of addon is activated, it will be visible on client panel side menu. |
status | Boolean | It specifies the current status of addons page. |
access_ps | Array | It specifies the access control of addon, ID numbers of authorization group are defined in it. |
settings | Array | It includes the data entered for configuration settings. |
Defining Configuration Fields
You should create a function with fields name in the class, returning value must be array.
Supported configuration field types include below:
- Text
- Password
- Confirmation Buttons
- Drop-Down Menus
- Circular (Radio) Select Buttons
- Text Fields
Below are examples of available parameters for each field type.
public function fields(){
$settings = isset($this->config['settings']) ? $this->config['settings'] : [];
return [
'example1' => [
'wrap_width' => 100,
'name' => "Text Box",
'description' => "Text Box Description",
'type' => "text",
'value' => isset($settings["example1"]) ? $settings["example1"] : "",
'placeholder' => "sample placeholder",
],
'example2' => [
'wrap_width' => 100,
'name' => "Password Box",
'description' => "Password Box Description",
'type' => "password",
'value' => isset($settings["example2"]) ? $settings["example2"] : "sample",
'placeholder' => "sample placeholder",
],
'example3' => [
'wrap_width' => 100,
'name' => "Approval Button",
'description' => "Approval Button Description",
'type' => "approval",
'checked' => isset($settings["example3"]) && $settings["example3"] ? true : false,
],
'example4' => [
'wrap_width' => 100,
'name' => "Dropdown Menu 1",
'description' => "Dropdown Menu 1 Description",
'type' => "dropdown",
'options' => "Option 1,Option 2,Option 3,Option 4",
'value' => isset($settings["example4"]) ? $settings["example4"] : "Option 2",
],
'example5' => [
'wrap_width' => 100,
'name' => "Dropdown Menu 2",
'description' => "Dropdown Menu 2 Description",
'type' => "dropdown",
'options' => [
'opt1' => "Option 1",
'opt2' => "Option 2",
'opt3' => "Option 3",
'opt4' => "Option 4",
],
'value' => isset($settings["example5"]) ? $settings["example5"] : "opt2",
],
'example6' => [
'wrap_width' => 100,
'name' => "Circular(Radio) Button 1",
'description' => "Circular(Radio) Button 1",
'width' => 40,
'description_pos' => 'L',
'is_tooltip' => true,
'type' => "radio",
'options' => "Option 1,Option 2,Option 3,Option 4",
'value' => isset($settings["example6"]) ? $settings["example6"] : "Option 2",
],
'example7' => [
'wrap_width' => 100,
'name' => "Circular(Radio) Button 2",
'description' => "Circular(Radio) Button 2 Description",
'description_pos' => 'L',
'is_tooltip' => true,
'type' => "radio",
'options' => [
'opt1' => "Option 1",
'opt2' => "Option 2",
'opt3' => "Option 3",
'opt4' => "Option 4",
],
'value' => isset($settings["example7"]) ? $settings["example7"] : "opt2",
],
'example8' => [
'wrap_width' => 100,
'name' => "Text Area",
'description' => "Text Area Description",
'rows' => "3",
'type' => "textarea",
'value' => isset($settings["example8"]) ? $settings["example8"] : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
'placeholder' => "sample placeholder",
],
];
}
Saving Configuration Fields
- You must create a function with save_fields name in the class, returning value must be array.
- In the parameter that comes to the function, it brings the values defined to the configuration field in the array data type.
- In the parameters, you must return the changes you made on function.
- In case of an error, return "false" in boolean data type, for the error message, you must use $this->error variable.
public function save_fields($fields=[]){
if(!isset($fields['example1']) || !$fields['example1']){
$this->error = $this->lang["error1"];
return false;
}
return $fields;
}