Skip to content

Commit

Permalink
Add displayVal method to ModelStructureProperty
Browse files Browse the repository at this point in the history
To serialize value instead of concatenating as if a list.
  • Loading branch information
mcaskill committed Nov 15, 2019
1 parent 8c68087 commit 01d48a5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Charcoal/Property/ModelStructureProperty.php
Expand Up @@ -580,6 +580,36 @@ public function save($val)
return $val;
}

/**
* @param mixed $val The value to to convert for display.
* @param array $options Optional display options.
* @return string
*/
public function displayVal($val, array $options = [])
{
if ($val === null || $val === '') {
return '';
}

/** Parse multilingual values */
if ($this['l10n']) {
$propertyValue = $this->l10nVal($val, $options);
if ($propertyValue === null) {
return '';
}
} elseif ($val instanceof Translation) {
$propertyValue = (string)$val;
} else {
$propertyValue = $val;
}

if (!is_scalar($propertyValue)) {
$propertyValue = json_encode($propertyValue, JSON_PRETTY_PRINT);
}

return (string)$propertyValue;
}

/**
* Inject dependencies from a DI Container.
*
Expand Down

0 comments on commit 01d48a5

Please sign in to comment.