FieldMappingFilter.php in Gutenberg 8
File
src/Plugin/Filter/FieldMappingFilter.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;
use Drupal\Core\Form\FormStateInterface;
class FieldMappingFilter 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('#((<!-- .*\\{.*"mappingField".*} -->)([\\s\\S]*?)(<!-- \\/[\\s\\S]*?-->)|(<!-- .*\\{.*"mappingField".*} \\/-->))#', [
$this,
'renderWithoutMappingFields',
], $text);
return new FilterProcessResult($text);
}
private function renderWithoutMappingFields($match) {
$comment_begin = $match[1];
$comment_end = $match[3];
return '';
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['enable_filter'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enabled'),
'#default_value' => $this->settings['enable_filter'],
];
return $form;
}
}