MappingFieldsFilter.php in Gutenberg 8
File
src/Plugin/Filter/MappingFieldsFilter.php
View source
<?php
namespace Drupal\gutenberg\Plugin\Filter;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MappingFieldsFilter extends FilterBase implements ContainerFactoryPluginInterface {
protected $renderer;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->renderer = $renderer;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('renderer'));
}
public function process($text, $langcode) {
$text = preg_replace_callback('#((<!-- .*\\{.*"mappingFields".*} -->)([\\s\\S]*?)(<!-- \\/[\\s\\S]*?-->)|(<!-- .*\\{.*"mappingFields".*} \\/-->))#', [
$this,
'renderWithoutMappingFields',
], $text);
return new FilterProcessResult($text);
}
private function renderWithoutMappingFields($match) {
$comment_begin = $match[1];
$comment_end = $match[3];
return '';
}
}