fixed thematiques display
This commit is contained in:
@@ -1,19 +1,39 @@
|
||||
scalar Violation
|
||||
|
||||
interface NodeInterface {
|
||||
id: Int!
|
||||
path: String!
|
||||
}
|
||||
|
||||
type Materiau implements NodeInterface {
|
||||
id: Int!
|
||||
uuid: String!
|
||||
title: String!
|
||||
path: String!
|
||||
author: String
|
||||
body: String
|
||||
bundle: String!
|
||||
}
|
||||
|
||||
interface SearchResultInterface {
|
||||
id: Int!
|
||||
uuid: String!
|
||||
title: String!
|
||||
path: String!
|
||||
author: String
|
||||
bundle: String!
|
||||
#
|
||||
short_description: String
|
||||
body: String
|
||||
linked_materials: [Materiau]
|
||||
}
|
||||
|
||||
type Materiau implements NodeInterface & SearchResultInterface{
|
||||
id: Int!
|
||||
uuid: String!
|
||||
title: String!
|
||||
path: String!
|
||||
author: String
|
||||
bundle: String!
|
||||
#
|
||||
short_description: String
|
||||
body: String
|
||||
linked_materials: [Materiau]
|
||||
#
|
||||
linked_articles: [Article]
|
||||
images: [Image]
|
||||
videos: [VideoLink]
|
||||
@@ -23,11 +43,28 @@ type Materiau implements NodeInterface {
|
||||
attachments: [Filefield]
|
||||
distributor: [Company]
|
||||
manufacturer: [Company]
|
||||
# famille: String
|
||||
# index: Int
|
||||
reference: String
|
||||
samples: [Sample]
|
||||
note: Note
|
||||
# famille: String
|
||||
# index: Int
|
||||
}
|
||||
|
||||
type Thematique implements NodeInterface & SearchResultInterface {
|
||||
id: Int!
|
||||
uuid: String!
|
||||
title: String!
|
||||
path: String!
|
||||
author: String
|
||||
bundle: String!
|
||||
#
|
||||
short_description: String
|
||||
body: String
|
||||
linked_materials: [Materiau]
|
||||
#
|
||||
images: [Image]
|
||||
tags: [Tag]
|
||||
memo: String
|
||||
}
|
||||
|
||||
type Article implements NodeInterface {
|
||||
@@ -36,6 +73,8 @@ type Article implements NodeInterface {
|
||||
title: String!
|
||||
path: String!
|
||||
author: String
|
||||
bundle: String!
|
||||
#
|
||||
body: String
|
||||
linked_materials: [Materiau]
|
||||
images: [Image]
|
||||
@@ -48,37 +87,24 @@ type Article implements NodeInterface {
|
||||
memo: String
|
||||
}
|
||||
|
||||
type Thematique implements NodeInterface {
|
||||
id: Int!
|
||||
uuid: String!
|
||||
title: String!
|
||||
path: String!
|
||||
author: String
|
||||
body: String
|
||||
linked_materials: [Materiau]
|
||||
images: [Image]
|
||||
tags: [Tag]
|
||||
memo: String
|
||||
}
|
||||
|
||||
type Note {
|
||||
id: Int!
|
||||
contenu: String
|
||||
target: Int
|
||||
}
|
||||
|
||||
type SearchResult {
|
||||
id: Int!
|
||||
uuid: String!
|
||||
title: String!
|
||||
bundle: String!
|
||||
path: String!
|
||||
short_description: String
|
||||
images: [Image]
|
||||
visuels: [Image]
|
||||
reference: String
|
||||
samples: [Sample]
|
||||
}
|
||||
# type SearchResult {
|
||||
# id: Int!
|
||||
# uuid: String!
|
||||
# title: String!
|
||||
# bundle: String!
|
||||
# path: String!
|
||||
# short_description: String
|
||||
# images: [Image]
|
||||
# visuels: [Image]
|
||||
# reference: String
|
||||
# samples: [Sample]
|
||||
# }
|
||||
|
||||
type Product {
|
||||
id: Int!
|
||||
|
@@ -11,7 +11,7 @@ extend type Query {
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
searchresults(ids: [Int], lang: String): [SearchResult]
|
||||
searchresults(ids: [Int], lang: String): [SearchResultInterface]
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
|
@@ -101,9 +101,17 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
$builder->compose(
|
||||
$builder->produce('route_load')
|
||||
->map('path', $builder->fromArgument('path')),
|
||||
$builder->callBack(function($parent, $args){
|
||||
$t="t";
|
||||
return $parent;
|
||||
}),
|
||||
$builder->produce('route_entity')
|
||||
->map('url', $builder->fromParent())
|
||||
->map('language', $builder->fromArgument('lang'))
|
||||
->map('language', $builder->fromArgument('lang')),
|
||||
$builder->callBack(function($parent, $args){
|
||||
$t="t";
|
||||
return $parent;
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
@@ -141,6 +149,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
->map('entity', $builder->fromParent())
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Materiau', 'bundle',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_bundle')
|
||||
->map('entity', $builder->fromParent())
|
||||
));
|
||||
|
||||
$registry->addFieldResolver('Materiau', 'path',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_url')
|
||||
@@ -319,6 +333,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
->map('path', $builder->fromValue('field_contenu.value'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Note', 'bundle',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_bundle')
|
||||
->map('entity', $builder->fromParent())
|
||||
));
|
||||
|
||||
$registry->addFieldResolver('Note', 'target',
|
||||
$builder->produce('property_path')
|
||||
->map('type', $builder->fromValue('entity:node'))
|
||||
@@ -332,6 +352,14 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
// \__ \/ -_) _` | '_/ _| ' \| / -_|_-< || | | _|
|
||||
// |___/\___\__,_|_| \__|_||_|_|_\___/__/\_,_|_|\__|
|
||||
protected function addSearchResult(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||
// Tell GraphQL how to resolve types of a common interface.
|
||||
$registry->addTypeResolver('SearchResultInterface', function ($value) {
|
||||
switch ($value->bundle()) {
|
||||
case 'materiau': return 'Materiau';
|
||||
case 'thematique': return 'Thematique';
|
||||
}
|
||||
throw new Error('Could not resolve content type.');
|
||||
});
|
||||
|
||||
$registry->addFieldResolver('Query', 'searchresults',
|
||||
$builder->produce('entity_load_multiple')
|
||||
@@ -339,69 +367,6 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
->map('ids', $builder->fromArgument('ids'))
|
||||
->map('language', $builder->fromArgument('lang'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'id',
|
||||
$builder->produce('entity_id')
|
||||
->map('entity', $builder->fromParent())
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'bundle',
|
||||
$builder->produce('entity_bundle')
|
||||
->map('entity', $builder->fromParent())
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'uuid',
|
||||
$builder->produce('entity_uuid')
|
||||
->map('entity', $builder->fromParent())
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'path',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_url')
|
||||
->map('entity', $builder->fromParent()),
|
||||
$builder->produce('url_path')
|
||||
->map('url', $builder->fromParent())
|
||||
)
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'title',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_label')
|
||||
->map('entity', $builder->fromParent())
|
||||
));
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'short_description',
|
||||
$builder->produce('property_path')
|
||||
->map('type', $builder->fromValue('entity:node'))
|
||||
->map('value', $builder->fromParent())
|
||||
->map('path', $builder->fromValue('field_short_description.value'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'images',
|
||||
$builder->produce('entity_reference')
|
||||
->map('entity', $builder->fromParent())
|
||||
->map('field', $builder->fromValue('field_materiau_images'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'visuels',
|
||||
$builder->produce('entity_reference')
|
||||
->map('entity', $builder->fromParent())
|
||||
->map('field', $builder->fromValue('field_visuel'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'reference',
|
||||
$builder->produce('property_path')
|
||||
->map('type', $builder->fromValue('entity:node'))
|
||||
->map('value', $builder->fromParent())
|
||||
->map('path', $builder->fromValue('field_reference.value'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('SearchResult', 'samples',
|
||||
$builder->produce('property_path')
|
||||
->map('type', $builder->fromValue('entity:node'))
|
||||
->map('value', $builder->fromParent())
|
||||
->map('path', $builder->fromValue('field_samples'))
|
||||
);
|
||||
}
|
||||
|
||||
// ___ _
|
||||
@@ -454,6 +419,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
)
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Article', 'bundle',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_bundle')
|
||||
->map('entity', $builder->fromParent())
|
||||
));
|
||||
|
||||
|
||||
$registry->addFieldResolver('Article', 'title',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_label')
|
||||
@@ -575,6 +547,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
// |_| |_||_\___|_|_|_\__,_|\__|_\__, |\_,_\___|
|
||||
// |_|
|
||||
protected function addThematique(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
|
||||
|
||||
$registry->addFieldResolver('Query', 'Thematique',
|
||||
$builder->produce('entity_load')
|
||||
->map('type', $builder->fromValue('node'))
|
||||
@@ -601,6 +574,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
)
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Thematique', 'bundle',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_bundle')
|
||||
->map('entity', $builder->fromParent())
|
||||
));
|
||||
|
||||
$registry->addFieldResolver('Thematique', 'title',
|
||||
$builder->compose(
|
||||
$builder->produce('entity_label')
|
||||
@@ -615,6 +594,13 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
||||
->map('entity', $builder->fromParent())
|
||||
));
|
||||
|
||||
$registry->addFieldResolver('Thematique', 'short_description',
|
||||
$builder->produce('property_path')
|
||||
->map('type', $builder->fromValue('entity:node'))
|
||||
->map('value', $builder->fromParent())
|
||||
->map('path', $builder->fromValue('field_short_description.value'))
|
||||
);
|
||||
|
||||
$registry->addFieldResolver('Thematique', 'body',
|
||||
$builder->produce('property_path')
|
||||
->map('type', $builder->fromValue('entity:node'))
|
||||
|
@@ -107,7 +107,7 @@ class Base extends ControllerBase {
|
||||
private function defaultQuery(){
|
||||
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
$this->query = $entity_storage->getQuery()
|
||||
->condition('type', 'materiau')
|
||||
->condition('type', ['materiau', 'thematique'], 'IN')
|
||||
->condition('status', '1')
|
||||
->range($this->offset, $this->limit)
|
||||
->accessCheck(TRUE)
|
||||
@@ -116,7 +116,7 @@ class Base extends ControllerBase {
|
||||
$this->results = $this->query->execute();
|
||||
|
||||
$this->count_query = $entity_storage->getQuery()
|
||||
->condition('type', 'materiau')
|
||||
->condition('type', ['materiau', 'thematique'], 'IN')
|
||||
->accessCheck(TRUE)
|
||||
->condition('status', '1')
|
||||
->count();
|
||||
@@ -191,18 +191,18 @@ class Base extends ControllerBase {
|
||||
$nids = [];
|
||||
// Using entityTypeManager
|
||||
// Get a node storage object.
|
||||
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
// $node_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
|
||||
foreach ($this->results as $result) {
|
||||
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
// $lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
// Load a single node.
|
||||
$node = $node_storage->load($result);
|
||||
// $node = $node_storage->load($result);
|
||||
// check if has translation
|
||||
|
||||
if ($node->hasTranslation($lang)) {
|
||||
// $uuids[] = $result->getField('uuid')->getValues()[0];
|
||||
// i used to filter like bellow because of a graphql probleme
|
||||
// if ($node->hasTranslation($lang)) {
|
||||
$nids[] = $result;
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
// $resp['uuids'] = $uuids;
|
||||
|
Reference in New Issue
Block a user