public function NumberFormat::tamper in Tamper 8
Tamper data.
Performs the operations on the data to transform it.
Parameters
mixed $data: The data to tamper.
\Drupal\tamper\TamperableItemInterface $item: Item that can be tampered as part of a plugin's execution.
Return value
mixed The tampered data.
Throws
\Drupal\tamper\Exception\TamperException When the plugin can not tamper the given data.
\Drupal\tamper\Exception\SkipTamperDataException When the calling tamper process should be skipped for the given data.
\Drupal\tamper\Exception\SkipTamperItemException When the calling tamper process should be skipped for the given item.
Overrides TamperInterface::tamper
File
- src/
Plugin/ Tamper/ NumberFormat.php, line 80
Class
- NumberFormat
- Plugin implementation for number format.
Namespace
Drupal\tamper\Plugin\TamperCode
public function tamper($data, TamperableItemInterface $item = NULL) {
if (!is_numeric($data)) {
throw new TamperException('Input should be numeric.');
}
$decimals = $this
->getSetting(self::SETTING_DECIMALS);
$dec_point = $this
->getSetting(self::SETTING_DEC_POINT);
$thousands_sep = $this
->getSetting(self::SETTING_THOUSANDS_SEP);
return number_format($data, $decimals, $dec_point, $thousands_sep);
}