Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
paragraphs_paste
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
paragraphs_paste
Merge requests
!3
Deleted Text.php file and updated composer.json
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Deleted Text.php file and updated composer.json
issue/paragraphs_paste-3271977:3271977-remove-basic-text
into
2.x
Overview
0
Commits
6
Pipelines
0
Changes
10
Merged
Elber Rodrigues
requested to merge
issue/paragraphs_paste-3271977:3271977-remove-basic-text
into
2.x
3 years ago
Overview
0
Commits
6
Pipelines
0
Changes
10
Expand
Closes
#3271977
0
0
Merge request reports
Compare
2.x
version 5
372c35fb
3 years ago
version 4
f5315c66
3 years ago
version 3
4e73744f
3 years ago
version 2
7de1dd21
3 years ago
version 1
2a687f24
3 years ago
2.x (base)
and
latest version
latest version
daea7a57
6 commits,
3 years ago
version 5
372c35fb
5 commits,
3 years ago
version 4
f5315c66
4 commits,
3 years ago
version 3
4e73744f
3 commits,
3 years ago
version 2
7de1dd21
2 commits,
3 years ago
version 1
2a687f24
1 commit,
3 years ago
10 files
+
72
−
283
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
10
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/ParagraphsPastePlugin/Text.php
+
36
−
44
Options
@@ -2,80 +2,72 @@
namespace
Drupal\paragraphs_paste\Plugin\ParagraphsPastePlugin
;
use
Drupal\Component\Utility\Html
;
use
Drupal\Core\Field\FieldDefinitionInterface
;
use
Drupal\paragraphs_paste
\ParagraphsPastePluginBase
;
use
Netcarver\Textile\Parser
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Defines the "text" plugin.
* Defines the "
custom_
text" plugin.
*
* @ParagraphsPastePlugin(
* id = "text",
* label = @Translation("Text"),
* label = @Translation("Text
text
"),
* module = "paragraphs_paste",
* weight =
-1
,
* weight =
0
,
* allowed_field_types = {"text", "text_long", "text_with_summary", "string",
* "string_long"}
* )
*/
class
Text
extends
ParagraphsPastePluginBase
{
/**
* The textile Parser.
*
* @var \Netcarver\Textile\Parser
*/
protected
$textileParser
;
/**
* {@inheritdoc}
*/
public
static
function
isApplicable
(
$input
,
array
$definition
)
{
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
$instance
=
parent
::
create
(
$container
,
$configuration
,
$plugin_id
,
$plugin_definition
);
$instance
->
setTextileParser
(
new
Parser
());
if
(
empty
(
trim
(
$input
)))
{
return
FALSE
;
}
return
$instance
;
}
return
!
empty
(
trim
(
self
::
cleanHtml
(
$input
)));
/**
* Sets the parser for this plugin.
*
* @param \Netcarver\Textile\Parser $parser
* The textile parser.
*/
protected
function
setTextileParser
(
Parser
$parser
)
{
$this
->
textileParser
=
$parser
;
}
/**
* {@inheritdoc}
*/
protected
function
formatInput
(
$value
,
FieldDefinitionInterface
$fieldDefinition
)
{
return
$this
->
parseTextileInput
(
$value
);
}
if
(
$fieldDefinition
->
getType
()
==
'string'
)
{
$value
=
html_entity_decode
(
$value
);
return
trim
(
preg_replace
(
'/\s+/'
,
' '
,
strip_tags
(
$value
)));
}
if
(
$fieldDefinition
->
getType
()
==
'string_long'
)
{
$value
=
html_entity_decode
(
$value
);
$lines
=
array_map
(
'trim'
,
explode
(
PHP_EOL
,
strip_tags
(
$value
)));
return
implode
(
PHP_EOL
,
$lines
);
}
// For 'text', 'text_long', 'text_with_summary', do:
// Clean newlines and empty paragraphs.
$value
=
preg_replace
(
'~[\r\n]+|<p[^>]*>([\s]| )*<\/p>~'
,
''
,
$value
);
// Remove trailing whitespace chars and fix html.
$value
=
rtrim
(
self
::
cleanHtml
(
$value
));
return
$value
;
/**
* {@inheritdoc}
*/
public
static
function
isApplicable
(
$input
,
array
$definition
)
{
return
!
empty
(
trim
(
$input
))
&&
class_exists
(
'\Netcarver\Textile\Parser'
);
}
/**
* Clean html.
*
* @param string $html
* Html string to clean.
*
* @return string
* Cleaned html.
* Use textile to parse input.
*/
protected
static
function
cleanHtml
(
$html
)
{
$document
=
Html
::
load
(
$html
);
$xpath
=
new
\DOMXPath
(
$document
);
// Remove empty html tags recursively.
while
((
$node_list
=
$xpath
->
query
(
'//*[not(node())]'
))
&&
$node_list
->
length
)
{
foreach
(
$node_list
as
$node
)
{
$node
->
parentNode
->
removeChild
(
$node
);
}
}
return
Html
::
serialize
(
$document
);
public
function
parseTextileInput
(
$input
)
{
$input
=
preg_replace
(
'~\r?\n~'
,
"
\n
"
,
$input
);
return
$this
->
textileParser
->
setBlockTags
(
TRUE
)
->
setRestricted
(
TRUE
)
->
parse
(
$input
);
}
}
Loading