You are here

public function XBBCodeTestPlugin::doProcess in Extensible BBCode 4.0.x

Same name and namespace in other branches
  1. 8.3 tests/xbbcode_test_plugin/src/Plugin/XBBCode/XBBCodeTestPlugin.php \Drupal\xbbcode_test_plugin\Plugin\XBBCode\XBBCodeTestPlugin::doProcess()

Create the actual output.

Tag plugins should override this function rather than ::process(), in order to let the metadata from sub-tags bubble up.

Parameters

\Drupal\xbbcode\Parser\Tree\TagElementInterface $tag: Tag element in the parse tree.

Return value

\Drupal\xbbcode\TagProcessResult Tag process result.

Overrides TagPluginBase::doProcess

File

tests/xbbcode_test_plugin/src/Plugin/XBBCode/XBBCodeTestPlugin.php, line 27

Class

XBBCodeTestPlugin
Renders a test tag.

Namespace

Drupal\xbbcode_test_plugin\Plugin\XBBCode

Code

public function doProcess(TagElementInterface $tag) : TagProcessResult {
  $attributes = [];
  foreach ($tag
    ->getAttributes() as $key => $value) {
    $escaped = $value instanceof MarkupInterface ? $value : Html::escape($value);
    $attributes[] = "data-{$key}=\"{$escaped}\"";
  }
  $attributes = implode(' ', $attributes);
  return (new TagProcessResult("<span {$attributes}>{$tag->getContent()}</span>"))
    ->addAttachments([
    'library' => [
      'xbbcode_test_plugin/library-plugin',
    ],
  ]);
}