refactored showrooms page

This commit is contained in:
2022-09-19 15:58:11 +02:00
parent e5c6b871db
commit 9f20d34f42
23 changed files with 378 additions and 65 deletions

View File

@@ -167,10 +167,13 @@ type Showroom {
id: Int!
uuid: String!
name: String!
description: String
images: [Image]
email: String
address: Address
country: Country
phone: String
website: Link
}
type Company {
@@ -247,6 +250,8 @@ type Image {
style_articlecardmedium_url: String
style_hd: ImageStyle
style_hd_url: String
style_showroomhome: ImageStyle
style_showroomhome_url: String
}
type ImageStyle {

View File

@@ -26,6 +26,10 @@ extend type Query {
thematique(id: Int!, lang: String): Thematique
}
extend type Query {
allshowrooms(lang: String): [Showroom]
}
extend type Query {
showroom(id: Int!, lang: String): Showroom
}

View File

@@ -902,6 +902,22 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
})
));
$registry->addFieldResolver('Image', 'style_showroomhome',
$builder->produce('image_derivative')
->map('entity', $builder->fromParent())
->map('style', $builder->fromValue('home_showroom'))
);
$registry->addFieldResolver('Image', 'style_showroomhome_url',
$builder->compose(
$builder->produce('image_derivative')
->map('entity', $builder->fromParent())
->map('style', $builder->fromValue('home_showroom')),
$builder->callback(function($parent, $args){
return $parent['url'];
})
));
}
// __ ___ _ _ _ _
@@ -979,11 +995,31 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
// \__ \ ' \/ _ \ V V / '_/ _ \/ _ \ ' \
// |___/_||_\___/\_/\_/|_| \___/\___/_|_|_|
protected function addShowroom(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'allshowrooms',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
$query = $entity_storage->getQuery()
->condition('vid', ['showroom'], 'IN')
->sort('tid')
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('taxonomy_term'))
->map('ids', $builder->fromParent())
->map('language', $builder->fromArgument('lang'))
)
);
$registry->addFieldResolver('Query', 'showroom',
$builder->produce('entity_load')
->map('type', $builder->fromValue('taxonomy_term'))
->map('bundles', $builder->fromValue(['showroom']))
->map('id', $builder->fromArgument('id'))
->map('language', $builder->fromArgument('lang'))
);
$registry->addFieldResolver('Showroom', 'id',
@@ -1001,6 +1037,12 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Showroom', 'description',
$builder->callback(function($parent, $args){
return $parent->getDescription();
})
);
$registry->addFieldResolver('Showroom', 'email',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
@@ -1022,6 +1064,26 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('path', $builder->fromValue('field_public_phone.value'))
);
$registry->addFieldResolver('Showroom', 'images',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_visuels'))
);
$registry->addFieldResolver('Showroom', 'website',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_website'))
);
$registry->addFieldResolver('Showroom', 'country',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:taxonomy_term'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_public_address'))
);
}
// _ _ _