Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
markdown_field_formatter
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
markdown_field_formatter
Commits
765fac41
Commit
765fac41
authored
3 months ago
by
Mourad Zitouni
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3479802
: Support textarea - applied changes from issue branch
parent
71435c42
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
markdown_field_formatter.info.yml
+1
-1
1 addition, 1 deletion
markdown_field_formatter.info.yml
src/Plugin/Field/FieldFormatter/MarkdownTextFormatter.php
+39
-0
39 additions, 0 deletions
src/Plugin/Field/FieldFormatter/MarkdownTextFormatter.php
with
40 additions
and
1 deletion
markdown_field_formatter.info.yml
+
1
−
1
View file @
765fac41
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
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldFormatter/MarkdownTextFormatter.php
0 → 100644
+
39
−
0
View file @
765fac41
<?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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment