Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
entity_usage_updater
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
entity_usage_updater
Commits
807d2a3c
Commit
807d2a3c
authored
7 months ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3512187
by alexpott: When removing a link field we should remove the entire value
parent
097dc8c6
No related branches found
No related tags found
1 merge request
!20
Resolve #3512187 "When removing a"
Pipeline
#445705
passed
7 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EntityUsageUpdater.php
+7
-1
7 additions, 1 deletion
src/EntityUsageUpdater.php
tests/src/Functional/LinkRemoverFormTest.php
+39
-0
39 additions, 0 deletions
tests/src/Functional/LinkRemoverFormTest.php
with
46 additions
and
1 deletion
src/EntityUsageUpdater.php
+
7
−
1
View file @
807d2a3c
...
...
@@ -313,6 +313,7 @@ class EntityUsageUpdater implements EntityUsageUpdaterInterface {
'@old_entity_type'
=>
$old_target
->
getEntityTypeId
(),
'@old_entity_id'
=>
$old_target
->
id
(),
]);
$context
[
'sandbox'
][
'filter_empty_items'
]
=
TRUE
;
self
::
processReferences
(
$old_target
,
$entity_type_id
,
$entity_id
,
$func
,
$log_message
,
$usages
,
$context
);
}
...
...
@@ -401,13 +402,18 @@ class EntityUsageUpdater implements EntityUsageUpdaterInterface {
$updater
=
$updater_manager
->
createInstance
(
$method
);
assert
(
$updater
instanceof
EntityUsageUpdaterPluginInterface
);
foreach
(
$new_translation
->
get
(
$reference
[
'field_name'
])
as
$item
)
{
$field
=
$new_translation
->
get
(
$reference
[
'field_name'
]);
assert
(
$field
instanceof
FieldItemListInterface
);
foreach
(
$field
as
$item
)
{
// Use entity_usage to verify if the target entity is in the field.
$old_target_string
=
$old_target
->
getEntityTypeId
()
.
'|'
.
$old_target
->
id
();
if
(
in_array
(
$old_target_string
,
$tracker
->
getTargetEntities
(
$item
),
TRUE
))
{
$func
(
$updater
,
$item
);
}
}
if
(
$context
[
'sandbox'
][
'filter_empty_items'
]
??
FALSE
)
{
$field
->
filterEmptyItems
();
}
}
catch
(
PluginException
$e
)
{
$context
[
'results'
][
'errors'
][]
=
$e
->
getMessage
();
...
...
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/LinkRemoverFormTest.php
+
39
−
0
View file @
807d2a3c
...
...
@@ -4,7 +4,10 @@ declare(strict_types=1);
namespace
Drupal\Tests\entity_usage_updater\Functional
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\filter\Entity\FilterFormat
;
use
Drupal\link\LinkItemInterface
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\Tests\entity_usage
\Traits\EntityUsageLastEntityQueryTrait
;
...
...
@@ -27,6 +30,7 @@ class LinkRemoverFormTest extends BrowserTestBase {
'field_ui'
,
'text'
,
'path'
,
'link'
,
'entity_usage_updater'
,
];
...
...
@@ -38,6 +42,35 @@ class LinkRemoverFormTest extends BrowserTestBase {
$this
->
drupalCreateContentType
([
'type'
=>
'page'
]);
// Create a field with settings to validate.
$link_storage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'test_links'
,
'entity_type'
=>
'node'
,
'type'
=>
'link'
,
'cardinality'
=>
3
,
'settings'
=>
[],
]);
$link_storage
->
save
();
$link_field
=
FieldConfig
::
create
([
'field_storage'
=>
$link_storage
,
'bundle'
=>
'page'
,
'settings'
=>
[
'title'
=>
DRUPAL_DISABLED
,
'link_type'
=>
LinkItemInterface
::
LINK_GENERIC
,
],
]);
$link_field
->
save
();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository
=
\Drupal
::
service
(
'entity_display.repository'
);
$display_repository
->
getFormDisplay
(
'node'
,
'page'
)
->
setComponent
(
'test_links'
,
[
'type'
=>
'link_default'
,
])
->
save
();
$display_repository
->
getViewDisplay
(
'node'
,
'page'
)
->
setComponent
(
'test_links'
,
[
'type'
=>
'link'
])
->
save
();
// Set up the filter formats used by this test.
$basic_html_format
=
FilterFormat
::
create
([
'format'
=>
'basic_html'
,
...
...
@@ -100,10 +133,14 @@ class LinkRemoverFormTest extends BrowserTestBase {
$this
->
drupalGet
(
'node/add/page'
);
$page
->
fillField
(
'title[0][value]'
,
'Node 3'
);
$page
->
fillField
(
'body[0][value]'
,
(
string
)
$node1
->
toLink
(
"Link"
,
options
:
[
'absolute'
=>
TRUE
])
->
toString
());
$page
->
fillField
(
'test_links[0][uri]'
,
'/node/1'
);
$page
->
fillField
(
'test_links[1][uri]'
,
'http://example.org'
);
$page
->
fillField
(
'test_links[2][uri]'
,
'/node/1'
);
$page
->
pressButton
(
'Save'
);
$assert_session
->
pageTextContains
(
'Node 3 has been created.'
);
$node3
=
$this
->
drupalGetNodeByTitle
(
'Node 3'
);
$this
->
assertSession
()
->
linkByHrefExists
(
$node1
->
toUrl
()
->
toString
());
$this
->
assertSession
()
->
linkByHrefExists
(
'http://example.org'
);
// Create node 4.
$this
->
drupalGet
(
'node/add/page'
);
...
...
@@ -185,6 +222,8 @@ class LinkRemoverFormTest extends BrowserTestBase {
// Check to see if the links have been removed.
$this
->
drupalGet
(
'node/3'
);
$this
->
assertSession
()
->
linkByHrefNotExists
(
$node1
->
toUrl
()
->
toString
());
$this
->
assertSession
()
->
linkByHrefExists
(
'http://example.org'
);
$this
->
drupalGet
(
'node/4'
);
$this
->
assertSession
()
->
linkByHrefNotExists
(
$node2
->
toUrl
()
->
toString
());
...
...
...
...
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
sign in
to comment