public function KeywordFilter::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/ KeywordFilter.php, line 194
Class
- KeywordFilter
- Plugin implementation for filtering based on a list of words/phrases.
Namespace
Drupal\tamper\Plugin\TamperCode
public function tamper($data, TamperableItemInterface $item = NULL) {
$match_func = $this
->getSetting(self::FUNCTION);
$match = FALSE;
$word_list = $this
->getSetting(self::WORD_LIST);
if (is_array($data)) {
foreach ($data as $value) {
if ($this
->match($match_func, $value, $word_list)) {
$match = TRUE;
break;
}
}
reset($data);
}
else {
$match = $this
->match($match_func, $data, $word_list);
}
if (!$match && empty($this
->getSetting(self::INVERT))) {
return '';
}
if ($match && !empty($this
->getSetting(self::INVERT))) {
return '';
}
return $data;
}