diff --git a/modules/stanford_graphql/src/Plugin/GraphQLCompose/FieldType/NameItem.php b/modules/stanford_graphql/src/Plugin/GraphQLCompose/FieldType/NameItem.php new file mode 100644 index 00000000..d9dca669 --- /dev/null +++ b/modules/stanford_graphql/src/Plugin/GraphQLCompose/FieldType/NameItem.php @@ -0,0 +1,41 @@ + $item->get('title')->getValue(), + 'given' => $item->get('given')->getValue(), + 'middle' => $item->get('middle')->getValue(), + 'family' => $item->get('family')->getValue(), + 'generational' => $item->get('generational')->getValue(), + 'credentials' => $item->get('credentials')->getValue(), + ]; + } + +} diff --git a/modules/stanford_graphql/src/Plugin/GraphQLCompose/SchemaType/NameType.php b/modules/stanford_graphql/src/Plugin/GraphQLCompose/SchemaType/NameType.php new file mode 100644 index 00000000..2cd479bf --- /dev/null +++ b/modules/stanford_graphql/src/Plugin/GraphQLCompose/SchemaType/NameType.php @@ -0,0 +1,66 @@ +moduleHandler->moduleExists('name')) { + return $types; + } + + $types[] = new ObjectType([ + 'name' => $this->getPluginId(), + 'description' => (string) $this->t('Smart Date data.'), + 'fields' => fn() => [ + 'title' => [ + 'type' => Type::string(), + 'description' => 'Title', + ], + 'given' => [ + 'type' => Type::string(), + 'description' => 'Given', + ], + 'middle' => [ + 'type' => Type::string(), + 'description' => 'Middle name(s)', + ], + 'family' => [ + 'type' => Type::string(), + 'description' => 'Family', + ], + 'generational' => [ + 'type' => Type::string(), + 'description' => 'Generational', + ], + 'credentials' => [ + 'type' => Type::string(), + 'description' => 'Credentials', + ], + ], + ]); + + return $types; + } + +} diff --git a/modules/stanford_graphql/stanford_graphql.module b/modules/stanford_graphql/stanford_graphql.module index cb473a46..a26c975d 100644 --- a/modules/stanford_graphql/stanford_graphql.module +++ b/modules/stanford_graphql/stanford_graphql.module @@ -13,7 +13,21 @@ use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeInterfac */ function stanford_graphql_graphql_compose_field_results_alter(array &$results, $entity, GraphQLComposeFieldTypeInterface $plugin, FieldContext $context) { $field_definition = $plugin->getFieldDefinition(); - if ($field_definition->getName() == 'layout_selection' && isset($results[0])) { - $results = [['id' => $results[0]?->id(), 'label' => $results[0]?->label()]]; + if ($field_definition->getName() == 'layout_selection') { + foreach ($results as &$result) { + $result = [ + 'id' => $results->id(), + 'label' => $results->label(), + ]; + } + } + + if ($field_definition->getType() == 'viewfield') { + /** @var \Drupal\views\ViewExecutable $result */ + foreach ($results as $result) { + // Change the view display to use the graphql that should match the chosen + // view. + $result->setDisplay($result->current_display . '_graphql'); + } } }