Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui_patterns_field_formatters
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
ui_patterns_field_formatters
Commits
05ddb76a
Commit
05ddb76a
authored
3 years ago
by
christian.wiedemann
Committed by
Edouard Cunibil
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISSUE-3251489
: Add update hook to migrate layout builder fields to new format.
parent
abb7a77f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ui_patterns_field_formatters.install
+46
-0
46 additions, 0 deletions
ui_patterns_field_formatters.install
with
46 additions
and
0 deletions
ui_patterns_field_formatters.install
+
46
−
0
View file @
05ddb76a
...
...
@@ -5,6 +5,7 @@
* UI Patterns Field Formatters updates.
*/
use
Drupal\layout_builder
\Entity\LayoutBuilderEntityViewDisplay
;
use
Drupal\ui_patterns
\Form\PatternDisplayFormTrait
;
/**
...
...
@@ -43,3 +44,48 @@ function ui_patterns_field_formatters_update_9001(&$sandbox) {
$sandbox
[
'#finished'
]
=
$sandbox
[
'progress'
]
/
$sandbox
[
'total'
];
}
/**
* Clean up existing formatters settings placed by layout builder.
*/
function
ui_patterns_field_formatters_update_9002
(
&
$sandbox
)
{
if
(
!
\Drupal
::
moduleHandler
()
->
moduleExists
(
'layout_builder'
))
{
return
;
}
$displayStorage
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'entity_view_display'
);
if
(
!
isset
(
$sandbox
[
'total'
]))
{
$sandbox
[
'ids'
]
=
$displayStorage
->
getQuery
()
->
execute
();
$sandbox
[
'total'
]
=
count
(
$sandbox
[
'ids'
]);
$sandbox
[
'progress'
]
=
0
;
}
$id
=
array_pop
(
$sandbox
[
'ids'
]);
$display
=
$displayStorage
->
load
(
$id
);
if
(
$display
instanceof
LayoutBuilderEntityViewDisplay
)
{
$sections
=
$display
->
getSections
();
foreach
(
$sections
as
$section
)
{
foreach
(
$section
->
getComponents
()
as
$component
)
{
$component_array
=
$component
->
toArray
();
if
(
isset
(
$component_array
[
'configuration'
][
'formatter'
][
'type'
]))
{
$definition
=
&
$component_array
[
'configuration'
][
'formatter'
];
if
(
$definition
[
'type'
]
===
'pattern_formatter'
||
$definition
[
'type'
]
===
'pattern_wrapper_entity_reference_formatter'
)
{
PatternDisplayFormTrait
::
processFormStateValues
(
$definition
[
'settings'
]);
$component
->
setConfiguration
(
$component_array
[
'configuration'
]);
$changed
=
TRUE
;
}
}
}
}
}
if
(
!
empty
(
$changed
))
{
$display
->
save
();
}
$sandbox
[
'progress'
]
++
;
$sandbox
[
'#finished'
]
=
$sandbox
[
'progress'
]
/
$sandbox
[
'total'
];
}
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