Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
entity_type_clone
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
entity_type_clone
Merge requests
!5
Issue with view mode and field group.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue with view mode and field group.
issue/entity_type_clone-3356406:issues_view_config
into
3.x
Overview
0
Commits
2
Pipelines
0
Changes
1
Merged
Diosbel Mezquía
requested to merge
issue/entity_type_clone-3356406:issues_view_config
into
3.x
2 years ago
Overview
0
Commits
2
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
3.x
3.x (base)
and
latest version
latest version
3a705d2b
2 commits,
2 years ago
1 file
+
54
−
27
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Controller/EntityTypeCloneController.php
+
54
−
27
Options
@@ -12,6 +12,11 @@ use Symfony\Component\HttpFoundation\JsonResponse;
*/
class
EntityTypeCloneController
extends
ControllerBase
{
/**
* Store validated displays with third-party settings.
*/
protected
static
$checkThirdPartySettings
=
[];
/**
* Replaces string values recursively in an array.
*/
@@ -45,36 +50,58 @@ class EntityTypeCloneController extends ControllerBase {
->
getStorage
(
$storage
)
->
load
(
$data
[
'values'
][
'show'
][
'entity_type'
]
.
'.'
.
$data
[
'values'
][
'show'
][
'type'
]
.
'.'
.
$mode
)
->
toArray
();
// Prepare the target form display.
$targetDisplay
=
EntityTypeCloneController
::
arrayReplace
(
$data
[
'values'
][
'show'
][
'type'
],
$data
[
'values'
][
'clone_bundle_machine'
],
$sourceDisplay
);
unset
(
$targetDisplay
[
'_core'
]);
// Generate new uuid.
$targetDisplay
[
'uuid'
]
=
\Drupal
::
service
(
'uuid'
)
->
generate
();
// Save the target display.
if
(
$display
===
'form'
)
{
// Save the form display.
\Drupal
::
configFactory
()
->
getEditable
(
'core.'
.
$storage
.
'.'
.
$data
[
'values'
][
'show'
][
'entity_type'
]
.
'.'
.
$data
[
'values'
][
'clone_bundle_machine'
]
.
'.'
.
$mode
)
->
setData
(
$targetDisplay
)
->
save
();
}
elseif
(
$display
===
'view'
)
{
// Save the view display.
$entityDisplay
=
\Drupal
::
service
(
'entity_display.repository'
)
->
getViewDisplay
(
$data
[
'values'
][
'show'
][
'entity_type'
],
$data
[
'values'
][
'clone_bundle_machine'
],
$mode
);
if
(
isset
(
$targetDisplay
[
'content'
][
$sourceFieldName
]))
{
$entityDisplay
->
setComponent
(
$sourceFieldName
,
$targetDisplay
[
'content'
][
$sourceFieldName
]);
// Just get enabled form and view display.
if
(
$sourceDisplay
[
'status'
])
{
// Prepare the target form display.
$targetDisplay
=
EntityTypeCloneController
::
arrayReplace
(
$data
[
'values'
][
'show'
][
'type'
],
$data
[
'values'
][
'clone_bundle_machine'
],
$sourceDisplay
);
unset
(
$targetDisplay
[
'_core'
]);
// Generate new uuid.
$targetDisplay
[
'uuid'
]
=
\Drupal
::
service
(
'uuid'
)
->
generate
();
// Save the target display.
if
(
$display
===
'form'
)
{
// Save the form display.
\Drupal
::
configFactory
()
->
getEditable
(
'core.'
.
$storage
.
'.'
.
$data
[
'values'
][
'show'
][
'entity_type'
]
.
'.'
.
$data
[
'values'
][
'clone_bundle_machine'
]
.
'.'
.
$mode
)
->
setData
(
$targetDisplay
)
->
save
();
}
// Hide the field if needed.
if
(
isset
(
$targetDisplay
[
'hidden'
][
$sourceFieldName
])
&&
(
int
)
$targetDisplay
[
'hidden'
][
$sourceFieldName
]
===
1
)
{
$entityDisplay
->
removeComponent
(
$sourceFieldName
);
elseif
(
$display
===
'view'
)
{
// Save the view display.
$entityDisplay
=
\Drupal
::
service
(
'entity_display.repository'
)
->
getViewDisplay
(
$data
[
'values'
][
'show'
][
'entity_type'
],
$data
[
'values'
][
'clone_bundle_machine'
],
$mode
);
// Add support for third party configuration in view modes like
// field_group, etc.
if
(
!
isset
(
self
::
$checkThirdPartySettings
[
$mode
]))
{
$third_party_settings
=
$sourceDisplay
[
'third_party_settings'
];
if
(
$third_party_settings
)
{
// Avoid future checks.
self
::
$checkThirdPartySettings
[
$mode
]
=
true
;
foreach
(
$third_party_settings
as
$module
=>
$third_data
)
{
if
(
is_array
(
$third_data
))
{
foreach
(
$third_data
as
$key
=>
$third_value
)
{
// Add to destination display.
$entityDisplay
->
setThirdPartySetting
(
$module
,
$key
,
$third_value
);
}
}
}
}
}
if
(
isset
(
$targetDisplay
[
'content'
][
$sourceFieldName
]))
{
$entityDisplay
->
setComponent
(
$sourceFieldName
,
$targetDisplay
[
'content'
][
$sourceFieldName
]);
}
// Hide the field if needed.
if
(
isset
(
$targetDisplay
[
'hidden'
][
$sourceFieldName
])
&&
(
int
)
$targetDisplay
[
'hidden'
][
$sourceFieldName
]
===
1
)
{
$entityDisplay
->
removeComponent
(
$sourceFieldName
);
}
// Save the display.
$entityDisplay
->
save
();
}
// Save the display.
$entityDisplay
->
save
();
return
new
JsonResponse
(
t
(
'Success'
));
}
return
new
JsonResponse
(
t
(
'Success'
));
}
}
Loading