Configuration for Nos\Orm\Model, used in Appdesk, Crud Controller or Inspectors.
Associative array:
data_mapping: | columns on Appdesk and Inspectors. |
---|---|
i18n: | Optional, common translation |
actions: | Optional, common actions on the Nos\Orm\Model. |
icons: | Optional, common icons related to the Nos\Orm\Model. |
Associative array where each key => value defines a column, all keys are optionals.
title: | Title of the grid column. If not set, column will not be displayed. |
||||
---|---|---|---|---|---|
column: | Default value is same as key. |
||||
search_column: | Default value is column key value. Defines on which SQL column search / order. |
||||
search_relation: | |||||
Default value is deduced from key (ex: rel->col). Relation to load (via related function on query). |
|||||
sorting_callback: | |||||
A closure function taking two parameters: the $query object and the $sortDirection. |
|||||
multiContextHide: | |||||
Hide grid column when items are filtered on more than one contexts. |
|||||
isSafeHtml: | If true, the content won’t be escaped when displayed (inside the grid). |
||||
value: | A closure function taking current item Nos\Orm\Model in first parameter. Overloads value displayed in the grid. |
||||
cellFormatters: | Associative array of cellFormatters for formatting column display. |
||||
preview_url: | allow to custom url of the current item (used through “visualise” action).
|
<?php
return array(
'data_mapping' => array(
'column_a' => array(
'title' => 'Column A',
'column' => 'col_a',
'multiContextHide' => true,
'cellFormatters' => array(
'center' => array(
'type' => 'css',
'css' => array('text-align' => 'center'),
),
),
),
'column_b' => array(
'title' => 'B',
'search_column' => 'col_b_search',
'search_relation' => 'rel',
'value' => function($item) {
return 'test';
},
),
// ...
),
);
In the following example, column_a is sent in json but is not displayed in the grid.
<?php
return array(
'data_mapping' => array(
'column_a',
),
);
In the following example, col_b is sent in json under the column_b key but is not displayed in the grid.
<?php
return array(
'data_mapping' => array(
'column_b' => 'col_b',
),
);
If the Model has the Orm_Behaviour_Twinnable behaviour, a pseudo column context is automatically added at the end of the data_mapping. But, if you want to place it elsewhere, you can force its position like this:
<?php
return array(
'data_mapping' => array(
'column_a' => array(
'title' => 'Column a'
),
'context',
'column_b' => array(
'title' => 'Column b'
),
),
// ...
);
This key contains all the common translations.
<?php
return array(
'i18n' => array(
// Crud
'notification item added' => __('Done! The item has been added.'),
'notification item saved' => __('OK, all changes are saved.'),
'notification item deleted' => __('The item has been deleted.'),
// General errors
'notification item does not exist anymore' => __('This item doesn’t exist any more. It has been deleted.'),
'notification item not found' => __('We cannot find this item.'),
// ... see the 'framework/config/i18n_common.config.php' file to include the appropriate keys depending on your item
),
);
This key contains all the common actions related to the model. 5 actions are automatically added:
add: | The Add model button located on the appdesk’s toolbar |
---|---|
edit: | The Edit button located on the grids and the crud’s toolbar |
delete: | The Delete button located on the grids and the crud’s toolbar |
visualise: | The Visualise button located on the grids and crud’s toolbar, if the item can be displayed in front-office. |
share: | The Share button located on the crud’s toolbar, if the item has the Nos\Orm_Behaviour_Sharable behaviour. |
The action key can be filled in two different ways.
The most common way is to use an associative array:
<?php
return array(
// ...
'actions' => array(
'action_1' => array(/* configuration */),
'action_2' => array(/* configuration */),
// ...
),
);
If you want to change the order in which the actions are displayed, two keys are to be defined:
list: | associative array of actions (similar to the previous actions key) |
---|---|
order: | array of action’s key defining their order |
<?php
return array(
// ...
'actions' => array(
'list' => array(
'action_1' => array(/* configuration */),
'action_2' => array(/* configuration */),
// ...
),
'order' => array(
'action_2',
'action_1'
),
),
);
Each action is an associative array. Key is the action ID, and value is an array defining the action configuration:
action: | which action is executed when clicking on the button (using nosAction). |
||||||||
---|---|---|---|---|---|---|---|---|---|
label: | Text associated with the action (either shown as text or in a tooltip). |
||||||||
primary: | Is it a primary action? Primary actions have a dedicated button, and secondary actions appears in the action drop down. |
||||||||
icon: | Icon of the action. It’s a jquery ui icon class, but without the leading ui-icon- string. |
||||||||
red: | Is it a red action? (especially used for ‘Delete’) |
||||||||
align: | Alignment of the button. Can be a string (begin or end) or a number (begin is equivalent to -10 and end is equivalent to 10). Defines actions default order (align in ascending order). |
||||||||
targets: | Where is the action displayed? This has no effect if the action is not visible (see below). There are 3 locations available:
|
||||||||
disabled: | Callback function or array of callback functions (the one taken into account is the first which doesn’t return false) that returns a boolean or a string defining if the action is disabled or not for an item (a string disable the action and the value is used as title). There is two sent parameters: the current $item, and $params containing the common configuration. |
||||||||
visible: | Callback function or array of callback functions (the one taken into account is the first which doesn’t return true) that returns a boolean defining if the action is visible or not on a context. There is only one parameter sent, an associative array:
|
<?php
return array(
'actions '=> array(
'action_id' => array(
'action' => array(
'action' => 'confirmationDialog',
'dialog' => array(
'contentUrl' => '{{controller_base_url}}delete/{{_id}}',
'title' => 'Delete',
),
),
'label' => __('Delete'),
'primary' => true,
'icon' => 'trash',
'red' => true,
'targets' => array(
'grid' => true,
'toolbar-edit' => true,
),
'disabled' => function($item) {
return false;
},
'visible' => function($params) {
return !isset($params['item']) || !$params['item']->is_new();
},
),
),
);
Default actions (such as add or edit) can be overloaded with this actions key. Arr::merge is used to merge defined actions with default actions.
To hide an action, set its value to false:
<?php
return array(
// ...
'actions '=> array(
'add' => false,
),
);
Placeholders are available in order to simplify action targets and labels. First, some placeholders are always available:
Additionally, all dataset keys can be used as placeholders.
This key contains all common icons related to the model. Structure is similar to the icons key of the Metadata configuration file :
<?php
return array(
'icons' => array(
64 => 'static/apps/noviusos_page/img/64/page.png',
32 => 'static/apps/noviusos_page/img/32/page.png',
16 => 'static/apps/noviusos_page/img/16/page.png',
),
);