|
@@ -29,6 +29,8 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
|
|
|
$this->addRouteResolver($registry, $builder);
|
|
|
|
|
|
+ $this->addTexts($registry, $builder);
|
|
|
+
|
|
|
$this->addTextsdepart($registry, $builder);
|
|
|
|
|
|
$this->addTextref($registry, $builder);
|
|
@@ -90,7 +92,7 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
if ($class === 'Node') {
|
|
|
switch ($value->bundle()) {
|
|
|
case 'texte': return 'Textref';
|
|
|
- case 'texte_prod': return 'TextProd';
|
|
|
+ case 'texte_prod': return 'Textprod';
|
|
|
}
|
|
|
}
|
|
|
throw new Error('Could not resolve content type.');
|
|
@@ -105,6 +107,33 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
));
|
|
|
}
|
|
|
|
|
|
+ protected function addTexts(ResolverRegistryInterface $registry, ResolverBuilder $builder){
|
|
|
+ // Tell GraphQL how to resolve types of a common interface.
|
|
|
+ $registry->addTypeResolver('TextInterface', function ($value) {
|
|
|
+ switch ($value->bundle()) {
|
|
|
+ case 'texte': return 'Textref';
|
|
|
+ case 'texte_prod': return 'Textprod';
|
|
|
+ }
|
|
|
+ throw new Error('Could not resolve content type.');
|
|
|
+ });
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Query', 'texts',
|
|
|
+ $builder->compose(
|
|
|
+ $builder->callback(function($parent, $arg){
|
|
|
+ $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
|
|
|
+ $query = $entity_storage->getQuery()
|
|
|
+ ->condition('type', ['texte', 'texte_prod'], 'IN')
|
|
|
+ ->accessCheck(TRUE);
|
|
|
+ $results = $query->execute();
|
|
|
+ return $results;
|
|
|
+ }),
|
|
|
+ $builder->produce('entity_load_multiple')
|
|
|
+ ->map('type', $builder->fromValue('node'))
|
|
|
+ ->map('ids', $builder->fromParent())
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// _____ _ ___ _
|
|
|
// |_ _|____ _| |_ ___ | \ ___ _ __ __ _ _ _| |_
|
|
@@ -178,6 +207,12 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('entity', $builder->fromParent())
|
|
|
));
|
|
|
|
|
|
+ $registry->addFieldResolver('Textref', 'bundle',
|
|
|
+ $builder->compose(
|
|
|
+ $builder->produce('entity_bundle')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ));
|
|
|
+
|
|
|
$registry->addFieldResolver('Textref', 'texte',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('entity:node'))
|
|
@@ -220,6 +255,13 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('path', $builder->fromValue('field_video'))
|
|
|
);
|
|
|
|
|
|
+ $registry->addFieldResolver('Textref', 'titre_ref',
|
|
|
+ $builder->produce('property_path')
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('field_titre'))
|
|
|
+ );
|
|
|
+
|
|
|
$registry->addFieldResolver('Textref', 'tags',
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
@@ -280,6 +322,12 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('entity', $builder->fromParent())
|
|
|
));
|
|
|
|
|
|
+ $registry->addFieldResolver('Textprod', 'bundle',
|
|
|
+ $builder->compose(
|
|
|
+ $builder->produce('entity_bundle')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ));
|
|
|
+
|
|
|
$registry->addFieldResolver('Textprod', 'texte',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('entity:node'))
|