Since version 5, Drupal provides filters, a mechanism to manipulate the value of a text filter before rendering. In Drupal 8, filters are implemented as plugins.
So, in order to have two (text) fields which can can manipulate the value before display, you would need to
- Create a custom filter (in a custom module)
- Define a text format specific for your two fields, configured to use your custom filter (and any other filter you still want to apply)
- On your content type, configure the two fields to use that text format
- ?
- Profit
You filter code would look like
namespace Drupal\celebrate\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
/**
* @Filter(
* id = "filter_ninjafart",
* title = @Translation("NinjaFart Filter"),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
* )
*/
class NinjaFartFilter extends FilterBase {
public function process($text, $langcode) {
$text = doSomethingWith($text);
return new FilterProcessResult($text);
}
}