Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
taxonomy_manager
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
taxonomy_manager
Merge requests
!8
#3244002
Add multilingual fields to term edit form
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
#3244002
Add multilingual fields to term edit form
issue/taxonomy_manager-3244002:2.0.x
into
2.0.x
Overview
5
Commits
1
Pipelines
0
Changes
2
4 open threads
Hide all comments
Closed
#3244002 Add multilingual fields to term edit form
Martin Malovanets
requested to merge
issue/taxonomy_manager-3244002:2.0.x
into
2.0.x
Feb 11, 2022
Overview
5
Commits
1
Pipelines
0
Changes
2
4 open threads
Hide all comments
0
0
Merge request reports
Compare
2.0.x
2.0.x (base)
and
latest version
latest version
f0ca91d0
1 commit,
Feb 11, 2022
2 files
+
83
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
src/Form/TaxonomyManagerForm.php
+
37
−
1
View file @ f0ca91d0
Edit in single-file editor
Open in Web IDE
Show full file
@@ -359,23 +359,59 @@ class TaxonomyManagerForm extends FormBase {
* AJAX callback handler for the term data form.
*/
public
function
termDataCallback
(
$form
,
FormStateInterface
$form_state
)
{
$taxonomy_term
=
$this
->
taxonomyTypeManager
->
load
(
$form_state
->
getValue
(
'load-term-data'
));
$translatable
=
\Drupal
::
config
(
'taxonomy_manager.settings'
)
->
get
(
'taxonomy_manager_translations'
);
$taxonomy_term
=
$this
->
taxonomyTypeManager
->
load
(
$form_state
->
getValue
(
'load-term-data'
));
$term_form
=
$this
->
entityFormBuilder
->
getForm
(
$taxonomy_term
,
'default'
);
$fields
=
\Drupal
::
service
(
'entity_field.manager'
)
->
getFieldDefinitions
(
$taxonomy_term
->
getEntityTypeId
(),
$taxonomy_term
->
bundle
());
// Move the term data form into a fieldset.
$term_form
[
'fieldset'
][
'#type'
]
=
'fieldset'
;
$term_form
[
'fieldset'
][
'#title'
]
=
Html
::
escape
(
$taxonomy_term
->
getName
())
.
' ('
.
$taxonomy_term
->
id
()
.
')'
;
$term_form
[
'fieldset'
][
'#attributes'
]
=
[];
foreach
(
Element
::
children
(
$term_form
)
as
$key
)
{
if
(
$key
!=
'fieldset'
)
{
$term_form
[
'fieldset'
][
$key
]
=
$term_form
[
$key
];
if
(
$translatable
&&
$key
!==
'langcode'
&&
isset
(
$fields
[
$key
]))
{
if
(
$fields
[
$key
]
->
isTranslatable
())
{
$widget
=
array_shift
(
$term_form
[
'fieldset'
][
$key
][
'widget'
]);
foreach
(
\Drupal
::
service
(
'language_manager'
)
->
getLanguages
()
as
$langcode
=>
$language
)
{
if
(
!
$language
->
isDefault
())
{
if
(
$taxonomy_term
->
hasTranslation
(
$langcode
))
{
$data
=
$taxonomy_term
->
getTranslation
(
$langcode
)
->
get
(
$key
)
->
getValue
();
foreach
(
$data
as
$delta
=>
$values
)
{
if
(
$widget
[
'#delta'
]
==
$delta
)
{
foreach
(
$values
as
$value_key
=>
$value
)
{
$widget
[
'value'
][
'#'
.
$value_key
]
=
$value
;
}
}
}
}
else
{
$widget
[
'value'
][
'#value'
]
=
''
;
}
$widget
[
'value'
][
'#name'
]
=
"taxonomy_manager_translations["
.
$key
.
"]["
.
$langcode
.
"]"
;
}
$widget
[
'value'
][
'#title'
]
=
$fields
[
$key
]
->
getLabel
()
.
" ("
.
$language
->
getName
()
.
")"
;
$term_form
[
'fieldset'
][
$key
][
'widget'
][
$langcode
]
=
$widget
;
}
}
}
unset
(
$term_form
[
$key
]);
}
}
$term_form
[
'#prefix'
]
=
'<div id="taxonomy-term-data-form">'
;
$term_form
[
'#suffix'
]
=
'</div>'
;
$current_path
=
$this
->
currentPath
->
getPath
();
// Change the form action url form the current site to the add form.
$term_form
[
'#action'
]
=
$this
->
urlGenerator
Loading