RenderTagPlugin.php in Extensible BBCode 4.0.x
File
src/Plugin/RenderTagPlugin.php
View source
<?php
namespace Drupal\xbbcode\Plugin;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\xbbcode\Parser\Tree\TagElementInterface;
use Drupal\xbbcode\TagProcessResult;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class RenderTagPlugin extends TagPluginBase implements ContainerFactoryPluginInterface {
protected $renderer;
public function __construct(array $configuration, string $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 doProcess(TagElementInterface $tag) : TagProcessResult {
$element = $this
->buildElement($tag);
$output = $this->renderer
->renderPlain($element);
$result = TagProcessResult::createFromRenderArray($element);
$result
->setProcessedText((string) $output);
return $result;
}
public abstract function buildElement(TagElementInterface $tag) : array;
}