Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WCMS
uw_migrate
Commits
570a1a8a
Commit
570a1a8a
authored
Dec 02, 2021
by
Chris Shantz
Browse files
Merge branch '1.0.x' into prod/1.0.x
parents
c46540c3
4b40a57f
Changes
9
Hide whitespace changes
Inline
Side-by-side
migrations/layout_builder/uw_field_body_no_summary_lb.yml
View file @
570a1a8a
...
...
@@ -37,6 +37,7 @@ process:
method
:
row
bid
:
plugin
:
uw_block_lookup
field
:
field_body_no_summary
source
:
ref_id
section
:
plugin
:
migration_lookup
...
...
migrations/layout_builder/uw_field_body_no_summary_sections_lb.yml
View file @
570a1a8a
...
...
@@ -37,6 +37,7 @@ process:
message
:
'
Destination
node
was
not
found.'
layout
:
layout
layout_settings
:
layout_settings
section
:
delta
destination
:
plugin
:
layout_builder:section
migration_dependencies
:
...
...
src/Plugin/migrate/process/UwDomInlineFileHandler.php
View file @
570a1a8a
...
...
@@ -3,12 +3,13 @@
namespace
Drupal\uw_migrate\Plugin\migrate\process
;
use
Drupal\Component\Utility\Html
;
use
Drupal\file\Entity\File
;
use
Drupal\media\MediaInterface
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Row
;
/**
*
Takes inline ref docs from rich text and makes them into media entiti
es.
*
Updates the URL for inline links to fil
es.
*
* Examples:
*
...
...
@@ -63,19 +64,22 @@ class UwDomInlineFileHandler extends UwFileDomProcessBase {
}
$file_uri
=
$this
->
getFileUri
(
$href
);
$
file
=
$this
->
loadFileByUri
(
$file_uri
);
$
media
=
$this
->
loadFileByUri
(
$file_uri
);
if
(
!
$
file
instanceof
MediaInterface
)
{
if
(
!
$
media
instanceof
MediaInterface
)
{
continue
;
}
// Create a new
DOM element for the document link in the text
.
$new_node
=
$this
->
document
->
createElement
(
'
drupal-media'
,
''
);
// Create a new
<a href> with an updated URL
.
$new_node
=
$this
->
document
->
createElement
(
'
a'
,
$html_node
->
nodeValue
);
// Load the file for this media item.
$file
=
$media
->
getSource
()
->
getSourceFieldValue
(
$media
);
$file
=
File
::
load
(
$file
);
// Attributes for the 'a' element.
$attributes
=
[
'data-entity-uuid'
=>
$file
->
uuid
(),
'data-entity-type'
=>
'media'
,
'data-caption'
=>
$html_node
->
nodeValue
,
'href'
=>
$file
->
createFileUrl
(),
];
foreach
(
$attributes
as
$attr
=>
$val
)
{
...
...
@@ -86,7 +90,7 @@ class UwDomInlineFileHandler extends UwFileDomProcessBase {
$dom_att
->
value
=
Html
::
escape
(
$val
);
$new_node
->
appendChild
(
$dom_att
);
}
// Replace the <a href> with
<drupal-media>
.
// Replace the
old
<a href> with
the new
.
$html_node
->
parentNode
->
replaceChild
(
$new_node
,
$html_node
);
}
return
$this
->
document
;
...
...
src/Plugin/migrate/process/UwMigrationLookupPath.php
View file @
570a1a8a
...
...
@@ -3,7 +3,9 @@
namespace
Drupal\uw_migrate\Plugin\migrate\process
;
use
Drupal\Component\Utility\UrlHelper
;
use
Drupal\Core\Site\Settings
;
use
Drupal\Core\Url
;
use
Drupal\file\FileInterface
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Row
;
...
...
@@ -54,9 +56,51 @@ class UwMigrationLookupPath extends UwNodeLookup {
$uri
=
&
$value
;
}
// Parse migration source settings, caching result.
static
$uw_migrate_settings
;
if
(
!
isset
(
$uw_migrate_settings
))
{
$uw_migrate_settings
[
'source'
]
=
parse_url
(
Settings
::
get
(
'uw_migrate_source'
));
// Normalize by removing trailing slash, if any.
$uw_migrate_settings
[
'source'
][
'path'
]
=
$uw_migrate_settings
[
'source'
][
'path'
]
??
NULL
;
$uw_migrate_settings
[
'source'
][
'path'
]
=
rtrim
(
$uw_migrate_settings
[
'source'
][
'path'
],
'/'
);
$uw_migrate_settings
[
'site_path'
]
=
Settings
::
get
(
'uw_migrate_site_path'
);
// Normalize by removing leading and trailing slashes, if any.
$uw_migrate_settings
[
'site_path'
]
=
trim
(
$uw_migrate_settings
[
'site_path'
],
'/'
);
}
$file
=
NULL
;
// If the URL is external and points to this site, convert to file or
// internal path. The protocol and host are optional, allowing relative
// URLs. If $uri does not match this site, leave it as-is.
if
(
preg_match
(
',^((?:(?:https?:)?//'
.
$uw_migrate_settings
[
'source'
][
'host'
]
.
')?'
.
$uw_migrate_settings
[
'source'
][
'path'
]
.
')?/('
.
$uw_migrate_settings
[
'site_path'
]
.
'/)?(.*)$,'
,
$uri
,
$matches
))
{
$path
=
$matches
[
3
];
// Path is to a file if this hunk, "sites/.../files", matches this site.
if
(
$matches
[
2
])
{
$file
=
$path
;
}
// If not a file but the URL is this site, convert $uri to internal path.
elseif
(
$matches
[
1
])
{
// When empty, the link is to the homepage.
$uri
=
$path
?:
'<front>'
;
}
}
// If it is a file path, try to load a File object with it. If it works, set
// $uri to the URL of that file.
if
(
$file
)
{
$file
=
$this
->
entityTypeManager
->
getStorage
(
'file'
)
->
loadByProperties
([
'uri'
=>
'public://'
.
$file
]);
$file
=
array_pop
(
$file
);
// Update $uri only if the file exists.
if
(
$file
instanceof
FileInterface
)
{
$uri
=
$file
->
createFileUrl
();
}
}
// Check if the url begins with http(s).
// UrlHelper::isExternal returns FALSE for "uwaterloo.ca" url.
if
(
!
UrlHelper
::
isExternal
(
$uri
)
&&
strpos
(
$uri
,
'.'
)
===
FALSE
)
{
else
if
(
!
UrlHelper
::
isExternal
(
$uri
)
&&
strpos
(
$uri
,
'.'
)
===
FALSE
)
{
// Mark link as internal.
$uri
=
'internal:/'
.
$uri
;
...
...
src/Plugin/migrate/source/UwEmbeddedContent.php
View file @
570a1a8a
...
...
@@ -37,8 +37,12 @@ abstract class UwEmbeddedContent extends UwTable {
// Include field values of supported content types.
$supported_node_types
=
[
'uw_web_page'
,
'uw_news_item'
,
'uw_event'
,
'uw_ct_person_profile'
,
'uw_blog'
,
'uw_ct_person_profile'
,
'uw_event'
,
'uw_news_item'
,
'uw_site_footer'
,
'uw_web_page'
,
];
$query
->
condition
(
'n.type'
,
$supported_node_types
,
'IN'
);
return
$query
;
...
...
src/Plugin/migrate/source/U
m
MenuLink.php
→
src/Plugin/migrate/source/U
w
MenuLink.php
View file @
570a1a8a
...
...
@@ -33,7 +33,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* source_module = "menu"
* )
*/
class
U
m
MenuLink
extends
MenuLink
{
class
U
w
MenuLink
extends
MenuLink
{
/**
* The menu link manager.
...
...
src/UwContentParser.php
View file @
570a1a8a
...
...
@@ -156,10 +156,12 @@ class UwContentParser {
// <em> HTML tag.
preg_match
(
'/<(footer|em)>.*<\/(footer|em)>/Us'
,
$quote_content
,
$matches
);
// These tags will be stripped from attribution content.
$attr_tags
=
[
'<footer>'
,
'</footer>'
,
'<cite>'
,
'</cite>'
];
$result
[]
=
[
// Strip out the attribution from quote content.
'content'
=>
empty
(
$matches
[
0
])
?
$quote_content
:
trim
(
str_replace
(
$matches
[
0
],
''
,
$quote_content
)),
'attribution'
=>
empty
(
$matches
[
0
])
?
''
:
trim
(
str
ip_tags
(
$matches
[
0
])),
'attribution'
=>
empty
(
$matches
[
0
])
?
''
:
trim
(
str
_replace
(
$attr_tags
,
''
,
$matches
[
0
])),
];
}
return
$result
;
...
...
tests/src/Kernel/UwMigrateTest.php
View file @
570a1a8a
...
...
@@ -689,12 +689,12 @@ class UwMigrateTest extends MigrateDrupal7TestBase {
// Copy text blocks.
$this
->
executeMigrations
([
'uw_cbl_copy_text'
]);
$this
->
assertSame
(
'7
4
'
,
$this
->
getEntityCount
(
'block_content'
));
$this
->
assertSame
(
'7
5
'
,
$this
->
getEntityCount
(
'block_content'
));
$this
->
executeMigration
(
'uw_field_body_no_summary_promo_item'
);
// We should have one more text block (promo item).
$this
->
assertSame
(
'7
5
'
,
$this
->
getEntityCount
(
'block_content'
));
$this
->
assertBlockContent
(
7
5
,
[
$this
->
assertSame
(
'7
6
'
,
$this
->
getEntityCount
(
'block_content'
));
$this
->
assertBlockContent
(
7
6
,
[
'type'
=>
[[
'target_id'
=>
'uw_cbl_copy_text'
]],
'field_uw_copy_text'
=>
[
[
...
...
@@ -749,6 +749,21 @@ class UwMigrateTest extends MigrateDrupal7TestBase {
],
$layout
->
getSection
(
10
)
->
getLayoutSettings
());
$this
->
assertSame
(
'uw_1_column'
,
$layout
->
getSection
(
11
)
->
getLayoutId
());
// Migrate body to layout builder for uw_site_footer.
$this
->
executeMigrations
([
'uw_field_body_no_summary_sections_lb'
,
'uw_field_body_no_summary_lb'
,
]);
// Load resulting layout.
$node
=
Node
::
load
(
19
);
$layout
=
$node
->
get
(
'layout_builder__layout'
);
// Test that it has 1 section.
$this
->
assertCount
(
1
,
$layout
->
getSections
());
// Test that the section has 1 block of type uw_cbl_copy_text.
$components
=
$layout
->
getSection
(
0
)
->
getComponents
();
$this
->
assertCount
(
1
,
$components
,
print_r
(
$components
,
1
));
$this
->
assertSame
(
'inline_block:uw_cbl_copy_text'
,
end
(
$components
)
->
getPluginId
());
// Webform migrations.
$this
->
executeMigration
(
'uw_webform'
);
$this
->
assertWebform
(
'webform_49'
,
[
...
...
tests/src/Kernel/process/UwBlockLookupTest.php
View file @
570a1a8a
...
...
@@ -27,6 +27,7 @@ class UwBlockLookupTest extends KernelTestBase {
'uw_migrate'
,
'migrate_plus'
,
'migrate_scanner'
,
'path_alias'
,
'pathauto'
,
'token'
,
];
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment