Skip to content

Commit

Permalink
Added the output format for values - "options".
Browse files Browse the repository at this point in the history
Analogous to "boolean", only any text or numeric values can act as a source value (often flags are stored in the database). The format allows you to specify different outputs depending on the value.

options: search.On the search|network.In networks

Look at this as an associative array in which the key is separated from the value by a dot. Array elements are separated by a vertical line.
  • Loading branch information
Sergey Zhidkov authored and duellsy committed Oct 27, 2019
1 parent 4e288ba commit e09256c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Venturecraft/Revisionable/FieldFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,29 @@ public static function datetime($value, $format = 'Y-m-d H:i:s')

return $datetime->format($format);
}

/**
* Format options
*
* @param string $value
* @param string $format
* @return string
*/
public static function options($value, $format)
{
$options = explode('|', $format);

$result = [];

foreach ($options as $option) {
$transform = explode('.', $option);
$result[$transform[0]] = $transform[1];
}

if (isset($result[$value])) {
return $result[$value];
}

return 'undefined';
}
}

0 comments on commit e09256c

Please sign in to comment.