Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds_migrate
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
feeds_migrate
Commits
6fc770ab
Commit
6fc770ab
authored
1 year ago
by
Youri van Koppen
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3377671
: Disable already mapped fields on the mapping add form.
parent
c2834437
No related branches found
No related tags found
1 merge request
!20
Issue #3377671: Disable already mapped fields on mapping add form
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/feeds_migrate_ui/src/Form/MigrationMappingFormBase.php
+32
-2
32 additions, 2 deletions
...es/feeds_migrate_ui/src/Form/MigrationMappingFormBase.php
with
32 additions
and
2 deletions
modules/feeds_migrate_ui/src/Form/MigrationMappingFormBase.php
+
32
−
2
View file @
6fc770ab
...
...
@@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityFieldManager;
use
Drupal\Core\Entity\EntityForm
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\SubformState
;
use
Drupal\Core\Security\TrustedCallbackInterface
;
use
Drupal\Core\Url
;
use
Drupal\feeds_migrate
\MappingFieldFormManager
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -15,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*
* @package Drupal\feeds_migrate\Form
*/
class
MigrationMappingFormBase
extends
EntityForm
{
class
MigrationMappingFormBase
extends
EntityForm
implements
TrustedCallbackInterface
{
const
CUSTOM_DESTINATION_KEY
=
'_custom'
;
...
...
@@ -80,6 +81,13 @@ class MigrationMappingFormBase extends EntityForm {
);
}
/**
* {@inheritdoc}
*/
public
static
function
trustedCallbacks
():
array
{
return
[
'postRender'
];
}
/**
* Gets the label for the destination field - if any.
*
...
...
@@ -157,6 +165,8 @@ class MigrationMappingFormBase extends EntityForm {
'effect'
=>
'fade'
,
'progress'
=>
'throbber'
,
],
'#post_render'
=>
[[
$this
,
'postRender'
]],
'#description'
=>
$this
->
t
(
'Note: fields that are disabled in the selection list are already mapped.'
),
];
$form
[
'general'
][
'destination_key'
]
=
[
...
...
@@ -201,6 +211,23 @@ class MigrationMappingFormBase extends EntityForm {
return
$form
;
}
/**
* Post render callback: disables already mapped destination fields.
*/
public
function
postRender
(
$rendered
,
$element
)
{
// Disable already mapped fields.
$mappings
=
$this
->
entity
->
getMappings
();
if
(
empty
(
$mappings
))
{
return
$rendered
;
}
foreach
(
array_keys
(
$mappings
)
as
$destination_field_id
)
{
$search
[]
=
'<option value="'
.
$destination_field_id
.
'">'
;
$replace
[]
=
'<option value="'
.
$destination_field_id
.
'" disabled="disabled">'
;
}
$rendered
=
str_replace
(
$search
,
$replace
,
$rendered
);
return
$rendered
;
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::actions().
*
...
...
@@ -380,7 +407,10 @@ class MigrationMappingFormBase extends EntityForm {
/** @var \Drupal\Core\Field\FieldDefinitionInterface[] $fields */
$fields
=
$this
->
entity
->
getDestinationFields
();
foreach
(
$fields
as
$field_name
=>
$field
)
{
$options
[
$field
->
getName
()]
=
$field
->
getLabel
();
$options
[
$field
->
getName
()]
=
$this
->
t
(
'@label (@id)'
,
[
'@label'
=>
$field
->
getLabel
(),
'@id'
=>
$field
->
getName
(),
]);
}
return
$options
;
...
...
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