Common¶
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. |
Data mapping¶
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. | |
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. |
<?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';
},
),
// ...
),
);
Particular cases¶
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'
),
),
// ...
);
I18n¶
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
),
);
Actions¶
This key contains all the common actions related to the model. 5 actions which 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’) |
||||||||
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 that returns a boolean defining if the action is disabled or not for an item. There is only one parameter sent: the current $item. |
||||||||
visible: | Callback function 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 and particular cases¶
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¶
Placeholders are available in order to simplify action targets and labels. First, some placeholders are always available:
- controller_base_url: URL of the crud controller
- model_label: generated from model class name
- _id: ID of the item
- _title: Title of the item
- _context: if the item has the Contextable behaviour
Additionally, all dataset keys can be used as placeholders.
Icons¶
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',
),
);