Skip to content

Commit

Permalink
Add support for default for image list columns
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers authored Aug 2, 2021
1 parent 750e21e commit dad1295
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/backend/widgets/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,12 +1201,14 @@ protected function evalTextTypeValue($record, $column, $value)
*/
protected function evalImageTypeValue($record, $column, $value)
{
$image = null;
$config = $column->config;

// Get config options with defaults
$width = isset($config['width']) ? $config['width'] : 50;
$height = isset($config['height']) ? $config['height'] : 50;
$options = isset($config['options']) ? $config['options'] : [];
$fallback = isset($config['default']) ? $config['default'] : null;

// Handle attachMany relationships
if (isset($record->attachMany[$column->columnName])) {
Expand All @@ -1221,11 +1223,15 @@ protected function evalImageTypeValue($record, $column, $value)
$image = $value;

// Assume all other values to be from the media library
} else {
} elseif (!empty($value)) {
$image = MediaLibrary::url($value);
}

if (!is_null($image)) {
if (!$image && $fallback) {
$image = $fallback;
}

if ($image) {
$imageUrl = ImageResizer::filterGetUrl($image, $width, $height, $options);
return "<img src='$imageUrl' width='$width' height='$height' />";
}
Expand Down

0 comments on commit dad1295

Please sign in to comment.