Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kontainer
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
kontainer
Commits
2fb039a1
Commit
2fb039a1
authored
1 month ago
by
Robin De Herdt
Committed by
Benjamin Cizej
1 month ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3499394
by robindh: Ajax issue on multilingual sites
parent
626b663a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!9
Multilingual compatibility for entity reference & media library widgets
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/Field/FieldWidget/KontainerReferenceItemWidget.php
+10
-8
10 additions, 8 deletions
...Plugin/Field/FieldWidget/KontainerReferenceItemWidget.php
src/Service/KontainerService.php
+10
-8
10 additions, 8 deletions
src/Service/KontainerService.php
with
20 additions
and
16 deletions
src/Plugin/Field/FieldWidget/KontainerReferenceItemWidget.php
+
10
−
8
View file @
2fb039a1
...
...
@@ -11,6 +11,7 @@ use Drupal\Core\Field\FieldItemListInterface;
use
Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Routing\RouteProviderInterface
;
use
Drupal\Core\Url
;
use
Drupal\kontainer\Service\KontainerServiceInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\Routing\Exception\RouteNotFoundException
;
...
...
@@ -87,12 +88,11 @@ class KontainerReferenceItemWidget extends EntityReferenceAutocompleteWidget {
public
function
formElement
(
FieldItemListInterface
$items
,
$delta
,
array
$element
,
array
&
$form
,
FormStateInterface
$form_state
)
{
$element
=
parent
::
formElement
(
$items
,
$delta
,
$element
,
$form
,
$form_state
);
try
{
$
createKontainerMediaPath
=
$this
->
routeProvider
->
g
et
RouteByName
(
'kontainer.create_media'
)
->
get
Path
()
;
$createKontainerMediaPathTrimmed
=
ltrim
(
$createKontainerMediaPath
,
'/'
);
$
url
=
Url
::
fromRoute
(
'kontainer.create_media'
);
$url
->
s
et
Option
(
'query'
,
[
'token'
=>
$this
->
csrfTokenGenerator
->
get
(
$url
->
getInternal
Path
()
),
]
);
$fieldMachineName
=
$items
->
getName
();
$csrfToken
=
$this
->
csrfTokenGenerator
->
get
(
$createKontainerMediaPathTrimmed
);
$element
[
'target_id'
][
'#attributes'
][
'readonly'
]
=
'readonly'
;
$element
[
'target_id'
][
'#attributes'
][
'data-kontainer-selector'
]
=
'kontainer-reference-'
.
$fieldMachineName
.
'-'
.
$delta
;
$element
[
'kontainer_button'
]
=
[
...
...
@@ -106,13 +106,15 @@ class KontainerReferenceItemWidget extends EntityReferenceAutocompleteWidget {
'#attached'
=>
[
'library'
=>
'kontainer/kontainer-lib'
,
'drupalSettings'
=>
[
'ajaxTrustedUrl'
=>
[
$createKontainerMediaPath
.
'?token='
.
$csrfToken
=>
TRUE
],
'ajaxTrustedUrl'
=>
[
$url
->
toString
(
TRUE
)
->
getGeneratedUrl
()
=>
TRUE
,
],
'kontainer'
=>
[
'kontainerUrl'
=>
$this
->
configFactory
->
get
(
'kontainer.settings'
)
->
get
(
'kontainer_url'
),
'token'
=>
$csrfToken
,
'createMediaPath'
=>
$
createKontainerMediaPathTrimmed
,
'token'
=>
$
this
->
csrfToken
Generator
->
get
(
$url
->
getInternalPath
())
,
'createMediaPath'
=>
$
url
->
getInternalPath
()
,
],
],
],
...
...
This diff is collapsed.
Click to expand it.
src/Service/KontainerService.php
+
10
−
8
View file @
2fb039a1
...
...
@@ -471,11 +471,11 @@ class KontainerService implements KontainerServiceInterface {
* {@inheritDoc}
*/
public
function
buildKontainerSelectButtonArray
(
string
$type
,
array
$attributes
):
array
{
$
createKontainerMediaPath
=
$this
->
routeProvider
->
g
et
RouteByName
(
'kontainer.create_media'
)
->
get
Path
()
;
$createKontainerMediaPathTrimmed
=
ltrim
(
$createKontainerMediaPath
,
'/'
);
$csrfToken
=
$this
->
csrfTokenGenerator
->
get
(
$createKontainerMediaPathTrimmed
);
$
url
=
Url
::
fromRoute
(
'kontainer.create_media'
);
$url
->
s
et
Option
(
'query'
,
[
'token'
=>
$this
->
csrfTokenGenerator
->
get
(
$url
->
getInternal
Path
()
),
]
);
$output
=
[
'#type'
=>
$type
,
'#value'
=>
'Kontainer select'
,
...
...
@@ -483,13 +483,15 @@ class KontainerService implements KontainerServiceInterface {
'#attached'
=>
[
'library'
=>
'kontainer/kontainer-lib'
,
'drupalSettings'
=>
[
'ajaxTrustedUrl'
=>
[
$createKontainerMediaPath
.
'?token='
.
$csrfToken
=>
TRUE
],
'ajaxTrustedUrl'
=>
[
$url
->
toString
(
TRUE
)
->
getGeneratedUrl
()
=>
TRUE
,
],
'kontainer'
=>
[
'kontainerUrl'
=>
$this
->
configFactory
->
get
(
'kontainer.settings'
)
->
get
(
'kontainer_url'
),
'token'
=>
$csrfToken
,
'createMediaPath'
=>
$
createKontainerMediaPathTrimmed
,
'token'
=>
$
this
->
csrfToken
Generator
->
get
(
$url
->
getInternalPath
())
,
'createMediaPath'
=>
$
url
->
getInternalPath
()
,
],
],
],
...
...
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