11. Extend AdminCenter - ihofmann/open-websoccer GitHub Wiki

Pages and extensions to the AdminCenter

This chapter shows how you can add new configuration settings or pages to the AdminCenter.

Add Configuration Parameters

For a new configuration parameter to appear in the AdminCenter under "Settings", add the following entry to your module configuration file module.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE module SYSTEM "../module.dtd">
<module version="1.0.0">
  
  <settings>
	  <setting id="my_new_configuration" category="general" type="number" default="10" />
  </settings>
  
</module>

The Attributes of the element setting have the following meaning:

  • id: Unique identifier of the parameter. Spaces not allowed.
  • category: Identifier under which tab the option shall appear in the AdminCenter. Give a non-existing value to create a new tab.
  • type: Specifies what values ​​are allowed to enter. Allowed types ​​are: text | number | email | boolean | password | url | select | textarea | timestamp | foreign_key | tags
  • default: The value to initially set until the user specifies a value.

The parameter will appear on the one hand on the admin page "Settings" and on the other hand can be read at model or controller classes as follows:

class MyModel implements IModel {
	private $_db;
	private $_i18n;
	private $_websoccer;
	
	public function __construct($db, $i18n, $websoccer) {
		$this->_db = $db;
		$this->_i18n = $i18n;
		$this->_websoccer = $websoccer;
	}
	
	public function renderView() {
		return TRUE;
	}
	
	public function getTemplateParameters() {
		$configValue = $this->_websoccer->getConfig("my_new_configuration");
		
		return array();
	}
	
}

or in Templates:

Configuration value: {{ env.getConfig("my_new_configuration") }}

To get a readable label for the settings page, you need a file in your module called adminmessages_en.xml. The above example would need following content:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE messages SYSTEM "../messages.dtd">
<messages>
	<message id="settings_label_my_new_configuration">My new option</message> 
	<message id="settings_label_my_new_configuration_help">Text, which will appear next to the form field.</message> 
	
</messages>

Database administration pages:

The software generates a complete management page for creating, listing, editing and deleting database entries. A new database table is referred to as "Entity" in the system. The administration page is generated by the following example configuration in the module.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE module SYSTEM "../module.dtd">
<module version="1.0.0">
  <admin>
	<adminpage id="myNewDbTable" 
		permissionrole="r_daten" 
		navcategory="website" 
		entity="myEntity">
		<entity dbtable="myNewDbTable">
			<overview edit="true" delete="true">
				<column id="entity_myEntity_column1" 
					type="text" 
					field="column1" 
					filter="true" sort="true" />
				<column id="entity_myEntity_column2" 
					type="number" 
					field="column2" 
					filter="true" sort="true" /> 
				<column id="entity_myEntity_column3" 
					type="boolean" 
					field="column3" 
					filter="true" /> 
			</overview>
			<editform>
				<field id="column1" type="text" required="true" />
				<field id="column2" type="number" required="true" />
				<field id="column3" type="boolean" />
				<field id="column4" type="textarea" />
			</editform>
			
		</entity>    
	</adminpage>	
  </admin>
</module>

The labels of the summary table, creation form and also for use on the website are defined in a separate file called entitymessages_en.xml. An example definition:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE messages SYSTEM "../messages.dtd">
<messages>
	<message id="entity_myEntity">My new Entity</message>
	<message id="entity_myEntity_column1">column 1</message>
	<message id="entity_myEntity_column2">column 2</message>
	<message id="entity_myEntity_column3">column 3</message>
	<message id="entity_myEntity_column4">column 4</message>
	<message id="entity_myEntity_column4_help">Help text for column 4</message>
</messages>

The generation of the administration pages has a variety of different options. The above code examples should demonstrate the basic functionality. Study and refer the existing module.xml to see how other pages were configured.

⚠️ **GitHub.com Fallback** ⚠️