Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
graphql_compose
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
graphql_compose
Merge requests
!67
Add availableLanguages field to nodes
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
Add availableLanguages field to nodes
issue/graphql_compose-3432965:3432965-available-languages-field
into
2.1.x
Overview
1
Commits
3
Pipelines
3
Changes
4
Closed
Add availableLanguages field to nodes
Cedric Lenders
requested to merge
issue/graphql_compose-3432965:3432965-available-languages-field
into
2.1.x
Mar 22, 2024
Overview
1
Commits
3
Pipelines
3
Changes
4
Closes
#3432965
0
0
Merge request reports
Compare
2.1.x
version 2
303ff229
Mar 23, 2024
version 1
03b012dc
Mar 22, 2024
2.1.x (base)
and
latest version
latest version
1489bb37
3 commits,
Apr 10, 2024
version 2
303ff229
2 commits,
Mar 23, 2024
version 1
03b012dc
1 commit,
Mar 22, 2024
4 files
+
179
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
modules/graphql_compose_available_translations/src/Plugin/GraphQL/DataProducer/AvailableLanguages.php
0 → 100644
+
58
−
0
View file @ 1489bb37
Edit in single-file editor
Open in Web IDE
<?php
namespace
Drupal\graphql_compose_available_translations\Plugin\GraphQL\DataProducer
;
use
Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase
;
use
Drupal\node\NodeInterface
;
/**
* Returns the translation strings.
*
* @DataProducer(
* id = "available_languages",
* name = @Translation("Load string translations"),
* description = @Translation("Loads a list of string translations."),
* produces = @ContextDefinition("any",
* label = @Translation("String translation connection")
* ),
* consumes = {
* "entity" = @ContextDefinition("entity:node",
* label = @Translation("Entity"),
* ),
* }
* )
*/
class
AvailableLanguages
extends
DataProducerPluginBase
{
/**
* Resolves the available languages.
*
* @param \Drupal\node\NodeInterface $node
* The current node.
*
* @return array
* An array of available languages.
*/
public
function
resolve
(
NodeInterface
$node
):
array
{
// Get the translation languages.
$languages
=
$node
->
getTranslationLanguages
();
$translations
=
[];
foreach
(
$languages
as
$language
)
{
// Check if node has an ID.
if
(
!
$node
->
id
())
{
continue
;
}
// Get the translated node for each language.
$translatedNode
=
$node
->
getTranslation
(
$language
->
getId
());
// Customize the logic to fetch available languages for the node.
$translations
[]
=
[
'url'
=>
(
string
)
$translatedNode
->
toUrl
()
->
toString
(
TRUE
)
->
getGeneratedUrl
(),
'language'
=>
(
string
)
$language
->
getId
(),
];
}
return
$translations
;
}
}
Loading