diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c56b741..9791cf245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* **Build 27x** (2015-06-xx) + - List columns now support specifying a `default` option used when the value would otherwise be null. + * **Build 272** (2015-06-27) - Protected images and their thumbnails are now supported in the back-end. - Editing CMS templates now support form fields that use AJAX. diff --git a/modules/backend/classes/ListColumn.php b/modules/backend/classes/ListColumn.php index e352ef35b..0ba9761b7 100644 --- a/modules/backend/classes/ListColumn.php +++ b/modules/backend/classes/ListColumn.php @@ -47,6 +47,11 @@ class ListColumn */ public $valueFrom; + /** + * @var string Specifies a default value when value is empty. + */ + public $defaults; + /** * @var string Custom SQL for selecting this record display value, * the @ symbol is replaced with the table name. @@ -134,6 +139,9 @@ class ListColumn if (isset($config['valueFrom'])) { $this->valueFrom = $config['valueFrom']; } + if (isset($config['default'])) { + $this->defaults = $config['default']; + } if (isset($config['select'])) { $this->sqlSelect = $config['select']; } diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 3f5367a5c..080051e87 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -783,6 +783,13 @@ class Lists extends WidgetBase $value = $this->{'eval'. studly_case($column->type) .'TypeValue'}($record, $column, $value); } + /* + * Apply default value. + */ + if (empty($value)) { + $value = $column->defaults; + } + /* * Extensibility */