mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 02:54:38 +00:00
mvc: refactor grid search to fetch descriptive values from the model instead of trying to reconstruct them.
This makes it easier for special model field types to translate values into human readable formats, also when not being presented to the user like that in a selector.
This commit is contained in:
parent
4b647fc3f3
commit
10c81a4eea
@ -127,22 +127,7 @@ class UIModelGrid
|
||||
$row['uuid'] = $record->getAttributes()['uuid'];
|
||||
foreach ($fields as $fieldname) {
|
||||
if ($record->$fieldname != null) {
|
||||
$row[$fieldname] = $record->$fieldname->getNodeData();
|
||||
if (is_array($row[$fieldname])) {
|
||||
$listItems = $row[$fieldname];
|
||||
$row[$fieldname] = '';
|
||||
foreach ($listItems as $fieldValue) {
|
||||
if ($fieldValue['selected'] == 1) {
|
||||
if ($row[$fieldname] != "") {
|
||||
$row[$fieldname] .= ',';
|
||||
}
|
||||
$row[$fieldname] .= $fieldValue['value'];
|
||||
}
|
||||
}
|
||||
if ($row[$fieldname] === null) {
|
||||
$row[$fieldname] = "";
|
||||
}
|
||||
}
|
||||
$row[$fieldname] = $record->$fieldname->getDescription();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -651,6 +651,17 @@ abstract class BaseField
|
||||
return (string)$this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return descriptive value of the item.
|
||||
* For simple types this is usually the internal value, complex types may return what this value represents.
|
||||
* (descriptions of selected items)
|
||||
* @return null|string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return (string)$this;
|
||||
}
|
||||
|
||||
/**
|
||||
* update model with data returning missing repeating tag types.
|
||||
* @param $data array structure containing new model content
|
||||
|
||||
@ -122,6 +122,20 @@ abstract class BaseListField extends BaseField
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
$items = [];
|
||||
foreach ($this->getNodeData() as $fieldValue) {
|
||||
if ($fieldValue['selected'] == 1) {
|
||||
$items[] = $fieldValue['value'];
|
||||
}
|
||||
}
|
||||
return implode(',', $items);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user