fixed thematiques display

This commit is contained in:
Bachir Soussi Chiadmi 2021-03-03 17:55:32 +01:00
parent 72ea56e313
commit 6485e3e27b
8 changed files with 611 additions and 134 deletions

View File

@ -15,6 +15,7 @@ dependencies:
- field.storage.node.field_famille
- field.storage.node.field_manufacturer
- field.storage.node.field_reference
- field.storage.node.field_short_description
- field.storage.node.field_tags
- field.storage.taxonomy_term.field_synonyms
- field.storage.node.field_thesaurus
@ -104,6 +105,14 @@ field_settings:
dependencies:
config:
- field.storage.node.field_reference
field_short_description:
label: 'Short description'
datasource_id: 'entity:node'
property_path: field_short_description
type: string
dependencies:
config:
- field.storage.node.field_short_description
name:
label: 'Manufacturer » Terme de taxonomie » Nom'
datasource_id: 'entity:node'
@ -234,6 +243,14 @@ field_settings:
dependencies:
module:
- node
type:
label: 'Type de contenu'
datasource_id: 'entity:node'
property_path: type
type: string
dependencies:
module:
- node
uid:
label: uid
datasource_id: 'entity:node'
@ -304,6 +321,7 @@ processor_settings:
- country_code_1
- field_famille
- field_reference
- field_short_description
- name
- name_1
- processed
@ -312,6 +330,7 @@ processor_settings:
- thesaurus_name
- thesaurus_synonyms
- title
- type
- uuid
title: true
alt: true

View File

@ -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!

View File

@ -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 {

View File

@ -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'))

View File

@ -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;

File diff suppressed because one or more lines are too long

View File

@ -1,23 +1,18 @@
fragment SearchResultFields on SearchResult {
fragment SearchResultFields on SearchResultInterface {
id
uuid
bundle
path
title
short_description
reference
path
... on Materiau{
images{
url
alt
style_cardmedium_url
style_hd_url
}
visuels{
url
alt
style_cardmedium_url
style_hd_url
}
reference
samples{
showroom{
name
@ -26,3 +21,12 @@ fragment SearchResultFields on SearchResult {
location
}
}
... on Thematique {
images{
url
alt
style_cardmedium_url
style_hd_url
}
}
}

View File

@ -11,7 +11,7 @@
</header>
<section class="images" v-switcher>
<figure
v-for="(img, index) in item.visuels"
v-for="(img, index) in item.images"
:key="img.url"
>
<img
@ -28,7 +28,7 @@
</figure>
</section>
<CoolLightBox
:items="item.visuels"
:items="item.images"
:index="lightbox_index"
srcName="style_hd_url"
:loop="true"
@ -54,7 +54,7 @@ export default {
blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
// loadingFlag: false,
lightbox_index: null,
alias: this.item.path.replace(/^.?\/thematique\//g, '')
alias: this.item.path.replace(/^.*\/thematique\//g, '')
}
},
// computed: {
@ -98,7 +98,7 @@ export default {
// }
// },
openThematique (e) {
console.log('openThematique', e);
console.log('openThematique', e, this.alias);
this.$router.push({
name:`thematique`,
params: { alias:this.alias }