Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
migrate_plus
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
migrate_plus
Commits
ce552ed8
Commit
ce552ed8
authored
2 years ago
by
Ivan Doroshenko
Committed by
Ivan Doroshenko
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3096393
by marvil07, Matroskeen: Support html5 parsing on dom plugin
parent
08096932
No related branches found
No related tags found
1 merge request
!8
Issue #3229479: Entity_lookup taxonomy_term restricted by VID
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/migrate/process/Dom.php
+21
-1
21 additions, 1 deletion
src/Plugin/migrate/process/Dom.php
tests/src/Unit/process/DomTest.php
+23
-0
23 additions, 0 deletions
tests/src/Unit/process/DomTest.php
with
44 additions
and
1 deletion
src/Plugin/migrate/process/Dom.php
+
21
−
1
View file @
ce552ed8
...
...
@@ -10,6 +10,7 @@ use Drupal\migrate\MigrateExecutableInterface;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\ProcessPluginBase
;
use
Drupal\migrate\Row
;
use
Masterminds\HTML5
;
/**
* Handles string to DOM and back conversions.
...
...
@@ -30,6 +31,9 @@ use Drupal\migrate\Row;
* declaration. Defaults to '1.0'.
* - encoding: (optional) The encoding of the document as part of the XML
* declaration. Defaults to 'UTF-8'.
* - import_method: (optional) What parser to use. Possible values:
* - 'html': (default) use dom extension parsing.
* - 'html5': use html5 parsing.
*
* @codingStandardsIgnoreStart
*
...
...
@@ -95,6 +99,10 @@ class Dom extends ProcessPluginBase {
if
(
!
in_array
(
$configuration
[
'method'
],
[
'import'
,
'export'
]))
{
throw
new
\InvalidArgumentException
(
'The "method" must be "import" or "export".'
);
}
$configuration
[
'import_method'
]
=
$configuration
[
'import_method'
]
??
'html'
;
if
(
!
in_array
(
$configuration
[
'import_method'
],
[
'html'
,
'html5'
]))
{
throw
new
\InvalidArgumentException
(
'The "import_method" must be "html" or "html5".'
);
}
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
configuration
+=
$this
->
defaultValues
();
$this
->
logMessages
=
(
bool
)
$this
->
configuration
[
'log_messages'
];
...
...
@@ -159,7 +167,19 @@ class Dom extends ProcessPluginBase {
}
$document
=
new
\DOMDocument
(
$this
->
configuration
[
'version'
],
$this
->
configuration
[
'encoding'
]);
$document
->
loadHTML
(
$html
);
switch
(
$this
->
configuration
[
'import_method'
])
{
case
'html5'
:
$html5
=
new
HTML5
([
'target_document'
=>
$document
,
'disable_html_ns'
=>
TRUE
,
]);
$html5
->
loadHTML
(
$html
);
break
;
case
'html'
:
default
:
$document
->
loadHTML
(
$html
);
}
if
(
$this
->
logMessages
)
{
restore_error_handler
();
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/process/DomTest.php
+
23
−
0
View file @
ce552ed8
...
...
@@ -42,6 +42,17 @@ final class DomTest extends MigrateProcessTestCase {
->
transform
(
$value
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
}
/**
* @covers ::__construct
*/
public
function
testInvalidImportMethod
()
{
$configuration
[
'method'
]
=
'import'
;
$configuration
[
'import_method'
]
=
'invalid'
;
$this
->
expectException
(
\InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'The "import_method" must be "html" or "html5".'
);
(
new
Dom
(
$configuration
,
'dom'
,
[]));
}
/**
* @covers ::import
*/
...
...
@@ -54,6 +65,18 @@ final class DomTest extends MigrateProcessTestCase {
$this
->
assertTrue
(
$document
instanceof
\DOMDocument
);
}
/**
* @covers ::import
*/
public
function
testImportMethodHtml5
():
void
{
$configuration
[
'method'
]
=
'import'
;
$configuration
[
'import_method'
]
=
'html5'
;
$value
=
'<p>A simple paragraph.</p>'
;
$document
=
(
new
Dom
(
$configuration
,
'dom'
,
[]))
->
transform
(
$value
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
$this
->
assertTrue
(
$document
instanceof
\DOMDocument
);
}
/**
* @covers ::import
*/
...
...
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