public function ConvertBoolean::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/ ConvertBoolean.php, line 128
Class
- ConvertBoolean
- Plugin implementation for converting text value to boolean value.
Namespace
Drupal\tamper\Plugin\TamperCode
public function tamper($data, TamperableItemInterface $item = NULL) {
// Copy field value in case 'pass' is set.
$match_field = $data;
$truth_value = $this
->getSetting(self::SETTING_TRUTH_VALUE);
$false_value = $this
->getSetting(self::SETTING_FALSE_VALUE);
// Convert match field, truth and false values to lowercase, if no match
// case required.
if (!$this
->getSetting(self::SETTING_MATCH_CASE)) {
$match_field = mb_strtolower($match_field);
$truth_value = mb_strtolower($truth_value);
$false_value = mb_strtolower($false_value);
}
if ($match_field == $truth_value) {
return TRUE;
}
if ($match_field == $false_value) {
return FALSE;
}
if ($this
->getSetting(self::SETTING_NO_MATCH) == 'pass') {
return $data;
}
return $this
->getSetting(self::SETTING_NO_MATCH);
}