Skip to content
Snippets Groups Projects
Commit 765fac41 authored by Mourad Zitouni's avatar Mourad Zitouni
Browse files

Issue #3479802: Support textarea - applied changes from issue branch

parent 71435c42
No related branches found
No related tags found
No related merge requests found
name: Markdown Field Formatter
description: Provides a Markdown field formatter for file fields.
description: Provides a Markdown field formatter for file and text fields.
dependencies:
- drupal:file
type: module
......
<?php
namespace Drupal\markdown_field_formatter\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use League\CommonMark\CommonMarkConverter;
/**
* Plugin implementation of the 'markdown_text' formatter.
*
* @FieldFormatter(
* id = "markdown_text",
* label = @Translation("Markdown Text"),
* field_types = {
* "string_long"
* }
* )
*/
class MarkdownTextFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$converter = new CommonMarkConverter([
'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#markup' => $converter->convert($item->value),
];
}
return $elements;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment