-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...custom/sul_profile/modules/sul_helper/src/Plugin/GraphQLCompose/FieldType/SulLinkItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\sul_helper\Plugin\GraphQLCompose\FieldType; | ||
|
||
use Drupal\Core\Field\FieldItemInterface; | ||
use Drupal\graphql\GraphQL\Execution\FieldContext; | ||
use Drupal\graphql_compose\Plugin\GraphQLCompose\FieldType\LinkItem; | ||
|
||
/** | ||
* | ||
*/ | ||
class SulLinkItem extends LinkItem { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolveFieldItem(FieldItemInterface $item, FieldContext $context) { | ||
$data = parent::resolveFieldItem($item, $context); | ||
/** @var \Drupal\Core\TypedData\Plugin\DataType\Map $item_options */ | ||
$item_options = $item->get('options')->getValue(); | ||
if ($item_options && isset($item_options['attributes']['aria-label'])) { | ||
$data['attributes']['ariaLabel'] = $item_options['attributes']['aria-label']; | ||
} | ||
return $data; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...ul_profile/modules/sul_helper/src/Plugin/GraphQLCompose/SchemaType/LinkAttributesType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\sul_helper\Plugin\GraphQLCompose\SchemaType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeSchemaTypeBase; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeSchemaType( | ||
* id = "LinkAttributes" | ||
* ) | ||
*/ | ||
class LinkAttributesType extends GraphQLComposeSchemaTypeBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTypes(): array { | ||
$types = []; | ||
|
||
$types[] = new ObjectType([ | ||
'name' => $this->getPluginId(), | ||
'description' => (string) $this->t('Link Attributes.'), | ||
'fields' => fn() => [ | ||
'ariaLabel' => [ | ||
'type' => Type::string(), | ||
'description' => (string) $this->t('Aria Label'), | ||
], | ||
'ariaLabelledBy' => [ | ||
'type' => Type::string(), | ||
'description' => (string) $this->t('Aria Labelled By'), | ||
], | ||
], | ||
]); | ||
|
||
return $types; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...ustom/sul_profile/modules/sul_helper/src/Plugin/GraphQLCompose/SchemaType/SulLinkType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\sul_helper\Plugin\GraphQLCompose\SchemaType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\SchemaType\LinkType; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* | ||
*/ | ||
class SulLinkType extends LinkType { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTypes(): array { | ||
$types = []; | ||
|
||
$types[] = new ObjectType([ | ||
'name' => $this->getPluginId(), | ||
'description' => (string) $this->t('A link.'), | ||
'fields' => fn() => [ | ||
'title' => [ | ||
'type' => Type::string(), | ||
'description' => (string) $this->t('The title of the link.'), | ||
], | ||
'url' => [ | ||
'type' => Type::string(), | ||
'description' => (string) $this->t('The URL of the link.'), | ||
], | ||
'internal' => [ | ||
'type' => Type::nonNull(Type::boolean()), | ||
'description' => (string) $this->t('Whether the link is internal to this website.'), | ||
], | ||
'attributes' => [ | ||
'type' => static::type('LinkAttributes'), | ||
'description' => (string) $this->t('Link attributes'), | ||
], | ||
], | ||
]); | ||
|
||
return $types; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters