Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
02:54
created

LanguageSwitchLinkActive   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveValues() 0 10 1
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\LanguageSwitch;
4
5
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
6
use Youshido\GraphQL\Execution\ResolveInfo;
7
8
/**
9
 * @GraphQLField(
10
 *   id = "language_switch_link_active",
11
 *   secure = true,
12
 *   name = "active",
13
 *   type = "Boolean",
14
 *   parents = {"LanguageSwitchLink"}
15
 * )
16
 */
17
class LanguageSwitchLinkActive extends FieldPluginBase {
0 ignored issues
show
Bug introduced by
There is one abstract method getPluginDefinition in this class; you could implement it, or declare this class as abstract.
Loading history...
18
19
  /**
20
   * {@inheritdoc}
21
   */
22
  protected function resolveValues($value, array $args, ResolveInfo $info) {
23
    /** @var \Drupal\Core\Language\LanguageInterface $context */
24
    $context = $value['context'];
25
    /** @var \Drupal\Core\Language\LanguageInterface $language */
26
    $language = $value['link']['language'];
27
28
    // Check if the link's language code matches the language from the current
29
    // url context used for retrieving the language switch links.
30
    yield $context->getId() === $language->getId();
31
  }
32
33
}
34