Adds the sharable behaviour on a Nos\Orm\Model.
Associative array of different types of data forming a content nuggets.
Keys can be one of DataCatcher constants.
Values are associative array.
value: A column name or a closure. See Examples. useTitle: Help label indicate which property of item is use as default value. options: Associative array of different options. Only for DataCatcher::TYPE_URL. possibles: Associative array of possibles values. Only for DataCatcher::TYPE_IMAGE.
Returns: | Array containing the default content nuggets of an item. |
---|
Parameters: |
|
---|---|
Returns: | The Model_Content_Nuggets of this item for the specified data catcher. |
Parameters: |
|
---|---|
Returns: | Orm_Behaviour_Sharable::$data if $property is null. Otherwise, property value with default fallback. |
Retrieves all the data catchers that can use the content nugget of this item (checks the required_data of a data catcher and ).
returns: All the valid data catchers for this item (keys are the data catcher names).
Retrieves all possible medias that can be associated with the item. Search for linked medias and images inserted in the WYSIWYGs.
returns: Associative array of all Model_Media, Model_Media ID in keys, of item.
Retrieves the personalised content nugget of a data catcher, merged with the default content nugget of the item.
param string $catcher: Data catchers ID. returns: Array A content nugget.
<?php
array(
\Nos\DataCatcher::TYPE_TITLE => array(
'value' => 'monk_name',
),
);
<?php
array(
\Nos\DataCatcher::TYPE_TITLE => array(
'value' => function($monkey) {
return $monkey->monk_name;
},
),
);
From the Monkey example application. config/model/monkey.config.php (we’re using a config file here, because we can’t put functions in a class property):
<?php
return array(
'behaviours' => array(
'Nos\Orm_Behaviour_Sharable' => array(
'data' => array(
\Nos\DataCatcher::TYPE_TITLE => array(
'value' => 'monk_name',
'useTitle' => __('Use monkey name'),
),
\Nos\DataCatcher::TYPE_URL => array(
'value' => function($monkey) {
$urls = $monkey->urls();
if (empty($urls)) {
return null;
}
reset($urls);
return key($urls);
},
'options' => function($monkey) {
return $monkey->urls();
},
),
\Nos\DataCatcher::TYPE_TEXT => array(
'value' => function($monkey) {
return $monkey->monk_summary;
},
'useTitle' => __('Use monkey summary'),
),
\Nos\DataCatcher::TYPE_IMAGE => array(
'value' => function($monkey) {
$possible = $monkey->possible_medias();
return Arr::get(array_keys($possible), 0, null);
},
'possibles' => function($monkey) {
return $monkey->possible_medias();
},
),
),
),
),
);