class LanguageTypeResolver in GraphQL 8.2
Same name and namespace in other branches
- 8 src/TypeResolver/LanguageTypeResolver.php \Drupal\graphql\TypeResolver\LanguageTypeResolver
Resolves the schema for the 'language' data type.
Hierarchy
- class \Drupal\graphql\TypeResolver\LanguageTypeResolver implements TypeResolverInterface
Expanded class hierarchy of LanguageTypeResolver
1 string reference to 'LanguageTypeResolver'
1 service uses LanguageTypeResolver
File
- src/
TypeResolver/ LanguageTypeResolver.php, line 15
Namespace
Drupal\graphql\TypeResolverView source
class LanguageTypeResolver implements TypeResolverInterface {
/**
* Static cache of the language schema definition.
*
* @var \Fubhy\GraphQL\Type\Definition\Types\ObjectType
*/
protected $languageType;
/**
* {@inheritdoc}
*/
public function applies($type) {
if ($type instanceof DataDefinitionInterface) {
return $type
->getDataType() === 'language';
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function resolveRecursive($type) {
if ($type instanceof DataDefinitionInterface && $type
->getDataType() === 'language') {
if (!isset($this->languageType)) {
$this->languageType = new ObjectType('Language', [
'id' => [
'type' => new NonNullModifier(Type::idType()),
'resolve' => [
__CLASS__,
'getId',
],
],
'name' => [
'type' => new NonNullModifier(Type::stringType()),
'resolve' => [
__CLASS__,
'getName',
],
],
'direction' => [
'type' => new NonNullModifier(Type::stringType()),
'resolve' => [
__CLASS__,
'getDirection',
],
],
'weight' => [
'type' => new NonNullModifier(Type::intType()),
'resolve' => [
__CLASS__,
'getWeight',
],
],
'locked' => [
'type' => new NonNullModifier(Type::booleanType()),
'resolve' => [
__CLASS__,
'isLocked',
],
],
'default' => [
'type' => new NonNullModifier(Type::booleanType()),
'resolve' => [
__CLASS__,
'isDefault',
],
],
]);
}
return $this->languageType;
}
return NULL;
}
/**
* Gets the name of the language.
*
* @param \Drupal\Core\TypedData\Plugin\DataType\Language
* The language object.
*
* @return string The human-readable name of the language (in the language that was
* The human-readable name of the language (in the language that was
* used to construct this object).
*/
public static function getName(Language $language) {
return $language
->getValue()
->getName();
}
/**
* Gets the ID (language code).
*
* @param \Drupal\Core\TypedData\Plugin\DataType\Language
* The language object.
*
* @return string
* The language code.
*/
public static function getId(Language $language) {
return $language
->getValue()
->getId();
}
/**
* Gets the text direction (left-to-right or right-to-left).
*
* @param \Drupal\Core\TypedData\Plugin\DataType\Language
* The language object.
*
* @return string
* Either self::DIRECTION_LTR or self::DIRECTION_RTL.
*/
public static function getDirection(Language $language) {
return $language
->getValue()
->getDirection();
}
/**
* Gets the weight of the language.
*
* @param \Drupal\Core\TypedData\Plugin\DataType\Language
* The language object.
*
* @return int
* The weight, used to order languages with larger positive weights sinking
* items toward the bottom of lists.
*/
public static function getWeight(Language $language) {
return $language
->getValue()
->getWeight();
}
/**
* Returns whether this language is the default language.
*
* @param \Drupal\Core\TypedData\Plugin\DataType\Language
* The language object.
*
* @return bool
* Whether the language is the default language.
*/
public static function isDefault(Language $language) {
return $language
->getValue()
->isDefault();
}
/**
* Returns whether this language is locked.
*
* @param \Drupal\Core\TypedData\Plugin\DataType\Language
* The language object.
*
* @return bool
* Whether the language is locked or not.
*/
public static function isLocked(Language $language) {
return $language
->getValue()
->isLocked();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LanguageTypeResolver:: |
protected | property | Static cache of the language schema definition. | |
LanguageTypeResolver:: |
public | function |
Overrides TypeResolverInterface:: |
|
LanguageTypeResolver:: |
public static | function | Gets the text direction (left-to-right or right-to-left). | |
LanguageTypeResolver:: |
public static | function | Gets the ID (language code). | |
LanguageTypeResolver:: |
public static | function | Gets the name of the language. | |
LanguageTypeResolver:: |
public static | function | Gets the weight of the language. | |
LanguageTypeResolver:: |
public static | function | Returns whether this language is the default language. | |
LanguageTypeResolver:: |
public static | function | Returns whether this language is locked. | |
LanguageTypeResolver:: |
public | function |
Overrides TypeResolverInterface:: |